DropDownListFor用法

来源:互联网 发布:数据挖掘基础教程 pdf 编辑:程序博客网 时间:2024/06/05 07:51

view

 

@Html.DropDownListFor(x => x.Position.Id, ((IEnumerable< Position >)ViewBag.PositionList).Select(s => new SelectListItem { Value = s.Id.ToString(), Text = s.Name }))
            @Html.ValidationMessageFor(x=>x.Position);

 

 

 

huozhe

 

@Html.DropDownListFor(x => x.Position.Id,new selectList(viewBag.list,"id","name"));

控制器

ViewBag.PositionList=biz.GetAll()