@foreach (var item in Model) { if (ViewBag.GetModel.ParentID == item.DictID) { <option value="@item.DictID" selected="selected">@item.DictType</option> } else { <option value="@item.DictID">@item.DictType</option> } }
if (id != null) //返回顺序 { DictionaryBLL BLL = new DictionaryBLL(); ViewBag.GetModel = BLL.GetModel((int)id); return View(BLL.GetModelList("ParentID = 0")); } else { return Content("错误!"); }
页面加载顺序
先加载
ViewBag.GetModel.ParentID
在加载
Model
在循环
@foreach (var item in Model)