In ASP.NET MVC can url parameter name be different than model's property name? [duplicate]
Possible Duplicate:
Asp.Net MVC 2 - Bind a model's property to a different named value
Given following url:
~/mycontroller/myaction/?REG_NAME=123
following action:
public ActionResult MyAction(ActionRequest model)
and model:
public class ActionRequest
{
[ThisIsTheAttributeNameImLookingFor("REG_NAME")]
public string RegisteredTo { get; set;}
}
How can I map model's property (RegisteredTo) to url parameter (REG_NAME) with different name?
Inheriting CustomModelBinderAttribute is not the option, as it can not be applied to properties.
No such attribute exists. You either use a custom model binder, or a custom TypeDescriptor.
You can it like this:
public class ActionRequest
{
private string REG_NAME { get; set;}
public string RegisteredTo { get { return REG_NAME; } set { this.REG_NAME = value; } ;}
}
精彩评论