2011-10-08 85 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) 
     { 

     } 
} 
相關問題