View:
@Html.DropDownListFor(model => model.ArticleTypeId,Model.ArticleTypeSelectList, "全部")
Models:
public class Article
{
public IEnumerable ArticleTypeSelectList {get; set; }
public void LoadArticleTypeList(IList ArticleTypeList)
{
ArticleTypeSelectList = new List();
List lists = new List();
foreach (Model.Dictionary item in ArticleTypeList)
{
SelectListItem child = new SelectListItem() { Text = item.DValue,Value = item.Id.ToString() };
lists.Add(child);
}
ArticleTypeSelectList = lists;
}
}
在新增和修改里,要先实例Models,new Article,加载这个方法
如:
//新增时:这个是展示页面用
public ActionResult SetTop_Add()
{
ArticleModels styleModel = new ArticleModels();
IList FileTypeList = NhSession.CreateQuery("from Dictionary whereDTypeName='ArticleType'").List();
styleModel.LoadArticleTypeList(FileTypeList);
styleModel.LoadStatus();
styleModel.OpUserName = MUser.UserName;
styleModel.OpDate = DateTime.Now.Date;
return View(styleModel);
}
注意:在显示和httppost里的都要写这段话,再把model传到View里