0
通常,当使用viewbags下拉列表时,它们包含一个id列和value列,但对于标题我必须将其更改为来自第三方应用程序,现在不是像以前一样工作。它呈现下拉回来,但是当我点击后退按钮并使用会话变量来重新填充表单的值不是为此设置的,因为性别它工作正常。将viewbag值和文本设置为相同的字段
public ActionResult _NewEmpDetails()
{
var sessionValues = Session["MySessionValues"] as MySessionValues;
ViewBag.NameTitle = new SelectList(db.vwInproTitle.ToList(), "Title", "Title");
ViewBag.Gender = new SelectList(db.vwLkUpGender.ToList(), "GenderID", "Gender");
Employee Employee = sessionValues.Employee;
return PartialView("_NewEmpDetails", Employee);
}
视图
<div style="display: table-cell;" class="tCell">
<div>@Html.LabelFor(model => model.Title) </div>
<div>@Html.DropDownListFor(model => model.Title, (SelectList)ViewBag.NameTitle, "Please select a title", new { @class = "dropdown", id = "txtTitle" })</div>
<div>@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" }) </div>
</div>
的性别是设置相同,唯一的区别在于,对于性别它有一个值和文本列。
当我加载员工的下拉框中的值是存在的,但如果我填写表格并移动到下一个,然后回到所有其他值填充除了标题。如果我提交表格的标题值IS存储,所以我知道这不是一个值丢失的问题。