2011-10-08 89 views
0

我有一个表格:ASP MVC 3如何将字段从表单映射到对象?

<form method="POST" action="test"> 
<input type="text" name="personFirstName" /> 
<input type="text" name="personLastName" /> 
... 
</form> 

另外,我下课时:

[Serializable] 
public class Person 
{ 
public string FirstName {get;set;} 
public string LastName {get;set;} 
} 

和我有ActionResult的:

public ActionResult(Person p) 
{ 
... 
} 

所以H ow在序列化Person对象中的表单而不重命名表单中的“名称”?有没有别名属性? (personFirstName - >名字,personLastName - >姓氏)

回答

0

您需要创建自己的自定义模型联编程序。

public class CustomModelBinder:DefaultModelBinder 
{ 
protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor) 
     { 

     } 
} 
相关问题