2013-04-28 187 views
1

當窗體中的字段名稱是點屬性時,我如何避免直接訪問Request.Form集合,因爲我製作了包含多種類型的視圖模型。模型綁定點屬性

現在我有這樣的方法:

public ActionResult ChangeLineQty(int id, int quantity) 

但模型綁定沒有看到Request.Form集合在數量變量,因爲該字段名稱顯示爲:NewOrderLine.Quantity

這種特殊表單是一種在後臺更新數量的AJAX表單,它僅使用orderLine的ID和新數量。

+0

** [請點擊這裏](http://stackoverflow.com/questions/17002022/is-there-any-good-reason-to-use- formcollection-instead-of-viewmodel)** – 2013-06-24 13:46:27

回答

0

請發表您的功能就像這

public ActionResult ChangeLineQty(int id, NewOrderLine objNewOrderLine) 
{ 
     int quantity=objNewOrderLine.Quantity; 
} 
+0

我使用@Html.Action來調用此操作。我可以傳遞一個完整的模型嗎?我雖然只能沿路線發送。 – 2013-04-29 15:53:58

+0

您可以傳遞模型作爲路由值像這樣@ Html.Action(「Actionname」,「Controllername」,Model)試試這個。更多信息請檢查這篇文章http://stackoverflow.com/questions/8608165/passing-model-到HTML的行動 – 2013-04-30 05:20:58