【问题标题】:Model Binding Dot Properties模型绑定点属性
【发布时间】:2013-04-28 22:15:55
【问题描述】:

当表单中的字段名称是点属性时,如何避免直接访问Request.Form集合,因为我已经制作了一个包含多种类型的视图模型。

现在我有了这个方法:

public ActionResult ChangeLineQty(int id, int quantity)

但是模型绑定器在 request.form 集合中看不到数量变量,因为字段名称显示为:NewOrderLine.Quantity

这个特殊的表单是一个在后台更新 Quantity 的 AJAX 表单,它只使用 orderLine 的 ID 和新的数量。

【问题讨论】:

标签: asp.net-mvc asp.net-mvc-4 model-binding


【解决方案1】:

请这样写你的函数

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

【讨论】:

  • 我使用@Html.Action 来调用这个动作。我可以传递一个完整的模型吗?我虽然只能发送路由值。
  • 您可以将模型作为路由值传递 像这样@Html.Action("Actionname","Controllername",Model) 试试这个。更多信息请查看此帖子stackoverflow.com/questions/8608165/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-10
  • 1970-01-01
  • 2021-12-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-11
相关资源
最近更新 更多