0
我有以下下拉列表中选择编辑观点:MVC3的SelectList的SelectedValue被显示,但在编辑视图中不返回
@Html.DropDownListFor(model => model.Size,
new SelectList(Enumerable.Empty<SelectListItem>(), "Size", "Size"),
Model.Size,
new { id = "WoodSize" })
@Html.ValidationMessageFor(model => model.Size)
控制器的相关的部分是:
[HttpPost]
public ActionResult Edit(Part part)
{
try
{
if (ModelState.IsValid)
{
unitOfWork.PartRepository.Update(part);
unitOfWork.Save();
return RedirectToAction("Index");
}
}
catch (DataException)
{
//Log the error (add a variable name after DataException)
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
}
return View(part);
的的SelectedValue是显示在Get上,但除非更改,否则它不会在Post上返回到控制器,并且更新失败。如果手动选择该值,则返回选择并且更新成功。似乎SelectValue实际上并没有选择任何东西,只是显示默认文本。
我不得不错过一些东西,但我对此感到茫然。