开发者

How do I pass Url Parameters on a POST?

开发者 https://www.devze.com 2022-12-25 02:29 出处:网络
I have a controller method with the following signature: [AcceptVerbs(HttpVerbs.Post)] public ActionResult UpdateValues(int id, MyViewModel[] array)

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?


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) %>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号