Lets say i have a route like the following
/{controller}/{action}/{id}
Is it possible to bind the id to a property in my model
public ActionResult Update(Model model)
{
model.Details.Id <-- Should contain the value from the route...
}
Where my model class is the following?
public class Model
{
public Details Details {get;set;}
}
public class Details
{
public int Id {get;set;}
}
You’ll want to create your own custom model binder.
To register your binder you add this to your
Application_Start()Your controller then looks exactly as you have it above. This is a very simplistic example but the easiest way to do it. I’ll be happy to provide any additional help.