I have the next form:
<form method="POST" action="test">
开发者_运维知识库<input type="text" name="personFirstName" />
<input type="text" name="personLastName" />
...
</form>
Also, I have next class:
[Serializable]
public class Person
{
public string FirstName {get;set;}
public string LastName {get;set;}
}
And I have the ActionResult:
public ActionResult(Person p)
{
...
}
So how to serialize form in Person object without rename "name" in form? Is there any alias attributes? (personFirstName -> FirstName, personLastName -> LastName)
You need to create your own custom model binder.
public class CustomModelBinder:DefaultModelBinder
{
protected override void BindProperty( ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor )
{
}
}
精彩评论