我正在使用包含下拉列表和模型的编辑页面。我想从viewbag设置下拉列表的seleted值。 但不能这样做。你能否提出任何其他方法呢?
在控制器中,我这样做了
ViewBag.TraineeId = _employeeService.GetEmployeeNamelist(SmartSession.CompanyId);
查看
<div id="AttributeDetails">
@foreach (var item in Model.TraineeAssignDetail)
{
@Html.Partial("~/Areas/HRM/Views/TraineeAssign/Partial.cshtml", item)
}
</div>
我使用@Html.Partial()
<div class="col-md-2 col-sm-2 col-xs-6">
@Html.DropDownList("TraineeId", new SelectList(ViewBag.TraineeId, "Id", "FullName", Model.TraineeId), "--Select--", new { @class = "form-control col-md-7 col-xs-12 default ddlErrorMsg", @id = "ddlMaterialGroupId" })
@Html.ValidationMessageFor(model => model.TraineeId)
</div>
请告诉我一些方法。enter image description here