-1

I have 2 tables tbl_client and tbl_branch linked with the client_id. I have created a ClientController and a BranchController.

Now I need to control the branch under client view. I have and ActionLink

@Html.ActionLink("Branch Management", "Index", "Branch", new {id = item.client_id},null)

This will redirect to Index view in branch controller, where the list of branches according to client id is filtered and return the view.

Now I have a create link in this view and I need to redirect it to the Create Page which will Create the Branch Under the Client currently active.

2 Answers2

0

just put the client_id in a viewbag from your Branch-> Index actionresult.

Public ActionResult Index(string id){
  ViewBag.ClientId=id;
}

now goto its view; Index.cshtml and say,

@Html.ActionLink("New Client", "Create", "Client", new {id = ViewBag.ClientId});
Irshu
  • 8,248
  • 8
  • 53
  • 65
  • I have used ViewBag as you suggested but I cannot redirect back to the same page after I go to Create Page .The ViewBag gets null value when I go back to the listing page – user3405577 Mar 14 '14 at 04:31
0

Just Make a Link into View as:

@Html.ActionLink("Branch Create", "Create", "Branch", new {id = item.client_id})

and on Server side (i.e. In Controller) use action as:

    //GET 
    public ActionResult Create(long Client_ID)
    {
        var NewBranch=new BranchViewModel{Client_ID=Client_ID};
        return View(NewBranch);
    }

    //POST
    [HttpPost]
    public ActionResult Create(BranchViewModel Branch)
    {
        //Code to Create New Entry
    }

Maybe this can help you.

Rahul
  • 2,309
  • 6
  • 33
  • 60
  • It doesnot take id = item.client_id in the ActionLink .. I have managed to use Model instead of client .. I have tried ViewBag too but no good – user3405577 Mar 14 '14 at 04:29