1

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.

Community
  • 1
  • 1
Pawel Lesnikowski
  • 6,264
  • 4
  • 38
  • 42
  • 2
    Yep, it's a duplicate. Although the second response is better, than the one marked as answer. Unless someone knows an easier way I vote to close. – Pawel Lesnikowski Aug 26 '11 at 13:39

2 Answers2

0

No such attribute exists. You either use a custom model binder, or a custom TypeDescriptor.

ulu
  • 5,872
  • 4
  • 42
  • 51
0

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; } ;}
}
Denis Elkhov
  • 166
  • 2
  • 9