我正在尝试将模型发布回控制器,但由于某种原因,控制器总是返回 NULL。我知道我在做一些明显错误的事情。它是什么?
但是,如果我从该模型发回特定属性,它就可以正常工作。
控制器:
[HttpPost]
public void MyAction(Company company)
{
System.Diagnostics.Debug.WriteLine("STUFF:" + company.dbName);
if(company.CompanyOptions!=null)foreach (var item in company.CompanyOptions.CompanyLicenseOptions.CompanyLicenseOptionsList) System.Diagnostics.Debug.WriteLine("STUFF:" + item);
else System.Diagnostics.Debug.WriteLine("STUFF IS NULL");
}
看法:
@model Domain.Entities.Company
@using (Html.BeginForm("MyAction", "Controller", FormMethod.Post))
{
foreach (var licensedFeature in Model.CompanyOptions.CompanyLicenseOptions.CompanyLicenseOptionsList)
{
@Html.CheckBox(licensedFeature.LicenseName, licensedFeature.IsLicensed, checkboxHtmlAttributes);
@licensedFeature.LicenseName
}
<input type="hidden" name="company" value="@Model"/>
<input id="submit_licenses" type="submit" style="display:none;" />
}