I implemented two actions :
The first action it renders Address view with consumer ID within URL :
This is the URL http://localhost:90/Consumer/Address?id=18755
[HttpGet]
public ActionResult Address(int id)
{
return View();
}
The second action it posts the Address form :
[HttpPost]
public ActionResult Address(FormCollection value)
{
int id = Convert.ToInt32(Request["id"]);
// Some code ...
return View();
}
When I fire save action I found ID is null, I would like to retrieve conusmer ID from Get action ?
You cannot retrieve it from the GET action because you are now executing the POST action. So you will have to post this parameter if you want to be able to retrieve it.
So for example if we suppose that your GET action rendered a view containing a
<form>that will be used to POST you could include the id as a hidden field inside this form. This way when the form is submitted it will be sent to the second action:Also in your POST action instead of doing some manual type conversions simply use the default model binder to do that for you. Define a view model:
and then have your POST action take this view model as action argument: