【发布时间】:2016-05-04 00:54:32
【问题描述】:
我有一个视图索引,它有两个表单,一个搜索表单和一个保存表单。它们都有绑定到同一个应用程序数据源的 DropDownList 控件,但这是它们唯一的共同点。
当我使用 POST 请求保存数据时,搜索表单中的 DDL 更改为与保存表单中的值相同的值,这不是我想要的操作。这是我的精简代码:
@model Models.InfoVM
@using (Html.BeginForm("Search", "MyController")) {
@Html.DropDownList("searchCodes", (IEnumerable<SelectListItem>)Application["Codes"], "--Select--")
}
@using (Html.BeginForm("Save", "MyController")) {
@Html.DropDownListFor(m => m.Code, (IEnumerable<SelectListItem>)Application["Codes"], Model != null ? Model.Code : "--Select--")
}
还有我的控制器操作:
[HttpPost]
public ActionResult Save([System.Web.Http.FromBody]InfoVM model) {
if (ModelState.IsValid) {
Repository.UpdateInfo(model);
}
return View("Index", model);
}
为什么会发生这种情况,我该如何打破两者之间的联系?由于我没有将搜索表单的 DDL 绑定到我绑定到页面的 Model,所以我没想到值会改变。
【问题讨论】:
标签: asp.net-mvc