开发者

How to change action parameters and get it to work without changing routing in asp.net mvc?

开发者 https://www.devze.com 2023-02-05 13:46 出处:网络
In my route I have something like this: controller/action/{id} To my knowledge this means it will call any action with the parameter id like the following:

In my route I have something like this:

controller/action/{id} 

To my knowledge this means it will call any action with the parameter id like the following:

public ActionResult Detail(string id) 
{
}

What do I have to do to make the following work without r开发者_如何学运维egistering the particular route in global.asax file:

public ActionResult Detail(string customerId) 
{
}


If you really don't want to rename the method parameter, you can use BindAttribute to tell MVC what its logical name should be:

public ActionResult Detail([Bind(Prefix = "id")] string customerId)


You can also pass customerId as query string, which is normally what I do:

<%: Html.ActionLink("Detail", "Detail", new { @customerId = Model.CustomerID}, null)%>

MVC does not enforce the routing, but rather try to resolve routing based on your url AND query string.


have a route like - controller/action/{customerId} or just rename the parameter customerId to id and then use it the particular way you want.

0

精彩评论

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