我:
ViewBag.ActivityTypeID = new SelectList(activityTypes, "ActivityTypeID","Name"
,workFlowDetail.ActivityTypeID);
并在视野中:
@Html.DropDownListFor(model => model.ActivityTypeID,new SelectList(ViewBag.ActivityTypeID,"Value","Text"), String.Empty)
@Html.ValidationMessageFor(model => model.ActivityTypeID)
我的编辑视图中的下拉列表未选择默认值(workFlowDetail.ActivityTypeID)
我该怎么做? 感谢
答案 0 :(得分:1)
此问题通常发生在MVC中,因为model.ActivityTypeID
和ViewBag.ActivityTypeID
共有ActivityTypeID
这就是问题发生的原因,只需更改Viewbag
名称,问题就会得到解决。
这将有效: -
控制器:
ViewBag.ActivityType = new SelectList(activityTypes, "ActivityTypeID","Name"
,workFlowDetail.ActivityTypeID);
查看:
@Html.DropDownListFor(model => model.ActivityTypeID,new SelectList(ViewBag.ActivityType,"Value","Text"), String.Empty)
@Html.ValidationMessageFor(model => model.ActivityTypeID)
答案 1 :(得分:0)
只需在视图中使用以下内容:
@ Html.DropDownList(" ActivityTypeID",ViewBag.ActivityTypeID as SelectList) @ Html.ValidationMessageFor(型号=> model.ActivityTypeID)