@Html.DropDownListFor 设置默认值

按需求设置

 

模型设置方法

 public IEnumerable<SelectListItem> GetSelectList(int? selectId){

 var model = from u in db.CaseTypes select new SelectListItem { Selected = (u.CaseTypeId == selectId), Text = u.CaseTyeName, Value = SqlFunctions.StringConvert((double)u.CaseTypeId) };

}

 

视图里面调用

 

  @Html.DropDownListFor(model => model.CaseTemp, Model.GetSelectList(Model.CaseTypeId))

 

其中casetemp是为了缓存不能接收字符串的casetypeid 这样就可以根据传进来的值设定selected的值了。

posted on 2013-04-24 17:38  Arvin Lai  阅读(5075)  评论(0编辑  收藏  举报