一,在控制器中写好数据绑定
//通过ID查找出整列的数据
Case.Models.Case theCase = db.Case.Find(id); ViewBag.CaseUser2 = theCase;二,在视图中
实例化一个变量
@{
ViewBag.Title = "Edit"; var thecase = ViewBag.CaseUser2 as Case.Models.Case;}三,则可以用ViewBag将里面的每一列数据选出来判断
@if (thecase.CaseUser2 == "" )
{ <div class="form-group"> @Html.LabelFor(model => model.CaseUser2, new { @class = "control-label col-md-2", style = "padding-top: 6px;" }) <div class="col-md-10"> @Html.DropDownList("CaseUser2", (SelectList)ViewData["CaseUserList2"], new { @class = "selectpicker", @data_style = "btn-default" }) @Html.ValidationMessageFor(model => model.CaseUser2) </div> </div> }