[英]Hidden fields of complex object not passing to controller
I am using the HTML helper HiddenFor
inside of a for
loop to bind some properties of a complex object back to my model. 我在for
循环中使用HTML帮助器HiddenFor
将复杂对象的某些属性绑定回我的模型。
If I interrogate the view, I can see the values are being set correct in the hidden fields, but when I submit my form, the values are null in the controller. 如果查询视图,则可以在隐藏字段中看到正确设置的值,但是当我提交表单时,控制器中的值为null。
VIEW 视图
@for (int i = 0; i < Model.CustomerSearchResponses.customers.Count; i++)
{
@Html.HiddenFor(m => m.CustomerSearchResponses.customers[i].name.first)
@Html.HiddenFor(m => m.CustomerSearchResponses.customers[i].name.last)
@Html.HiddenFor(m => m.CustomerSearchResponses.customers[i].name.company)
@Html.HiddenFor(m => m.CustomerSearchResponses.customers[i].address.line1)
@Html.HiddenFor(m => m.CustomerSearchResponses.customers[i].address.line2)
@Html.HiddenFor(m => m.CustomerSearchResponses.customers[i].address.city)
@Html.HiddenFor(m => m.CustomerSearchResponses.customers[i].address.stateProvince)
@Html.HiddenFor(m => m.CustomerSearchResponses.customers[i].address.postalCode)
@Html.HiddenFor(m => m.CustomerSearchResponses.customers[i].address.country)
}
<input id="CustomerSearchResponses_customers_0__name_first" name="CustomerSearchResponses.customers[0].name.first" type="hidden" value="BRIAN">
MODEL 模型
public class RequestViewModel
{
**some other props**
public CustomerSearchResponse CustomerSearchResponses { get; set; }
}
CONTROLLER 控制器
[HttpPost]
public ActionResult QASAddress(RequestViewModel model, string previousButton, string submitButton)
{
// Do Stuff
}
Not all hidden fields are posted here for the sake of length, but they are all setting correctly. 出于篇幅考虑,并非所有隐藏字段都张贴在此处,但是它们都设置正确。 When I POST my form, the CustomerSearchResponses.customers[i]
object is there, but the name
and address
objects are null. 发布表单时,出现了CustomerSearchResponses.customers[i]
对象,但是name
和address
对象为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.