2013-04-28 80 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