views:

65

answers:

1

I have a controller method with the following signature:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateValues(int id, MyViewModel[] array)
{
}

The id is normally picked up as part of the Url on other GET controller methods (I have a working route that does this)

I am successfully passing the array1 from the form in my view to the controller method, but how do I also put the id onto my Url so that when the user clicks the Submit button, the controller method will pick up the id?

+1  A: 

The id parameter might be set to optional: ASP.NET MVC 2 Optional URL Parameters which is default in ASP.NET MVC 2 so if there is not form element named "id" it will not be passed.

Just pass the parameter you need as part of the form instead of part of the Url, as in:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateValues(int UserID, MyViewModel[] array)
{
}

and in your view:

<%= Html.Hidden("userID", Model.UserID) %>
Giorgi