我有一个包含大约50个字段的表单,使用默认和DevExpress编辑器的组合。我也使用knockout将文本框值绑定到跨度以进行计算。页面呈现正常,但是当我尝试发布以保存更新时,控制器的后期操作不会被点击,页面会重新加载旧值可见。
我无法发布确切的页面,但我可以发布剪辑 -
Index.cshtml:
@using(Html.BeginForm())
{
<b>Comapny:</b> @Html.Partial("_CompanyComboBox", Model)
<br />
@Html.Partial("_CompanyEditor", Model)
}
CompanyMonitoringController.cs:
[Route("CompanyMonitoring/{companyID:int?}")]
public ActionResult Index(int? companyID = null)
{
var companies = this.CompanyRepository.GetCompanies().OrderBy(c => c.CoShtName);
Company selectedComapny = companyID != null ? companies.Where(c => c.CompanyID == companyID).Single() : companies.First();
CompanyModel model = new CompanyModel(this.CompanyRepository.GetCompany(selectedComapny.CompanyID));
PopulateLists(model, companies);
return View(model);
}
[HttpPost]
public ActionResult Index([ModelBinder(typeof(DevExpressEditorsBinder))]CompanyModel model)
{
if (ModelState.IsValid)
{
this.CompanyRepository.SaveCompany(model.ToCompany());
return RedirectToAction("Index", new { companyID = model.CompanyID });
}
PopulateLists(model);
return View(model);
}
答案 0 :(得分:1)
我的一位同事回答了这个问题。
[HttpGet]
添加到索引获取方法[Route("CompanyMonitoring/{companyID:int?}")]]
添加到Index post方法。