2011-10-10 16 views
3

,我會用下面的代碼以使客戶模型的結合,綁定模型一般明確

[HttpPost] 
public ActionResult Create(Customer model) 
{ 
    ... 
} 

現在,我想提出的結合後,不是立即,這樣

[HttpPost] 
public ActionResult Create() 
{ 
    //some operations first 
    ... 
    //binding will start here 
    var model={Bind - To - Customer} 
    ... 
} 

那麼,我怎麼能做到這一點,是否有可能?

感謝很多的任何建議

回答

6

您可以使用UpdateModelTryUpdateModel方法:

[HttpPost] 
public ActionResult Create() 
{ 
    //some operations first 
    ... 
    // binding will start here 
    var model = new Customer(); 
    UpdateModel(customer); 
    ... 
}