开发者

In ASP.NET MVC can url parameter name be different than model's property name? [duplicate]

This question already has answer开发者_如何学Pythons here: Closed 11 years ago.

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; } ;}
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜