Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 registering the particular route in global.asax file:

public ActionResult Detail(string customerId) 
{
}
like image 293
johndoe Avatar asked Jan 20 '11 16:01

johndoe


1 Answers

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)
like image 195
Levi Avatar answered Oct 06 '22 01:10

Levi