Tim*_*sen 4 model-view-controller asp.net-mvc telerik asp.net-mvc-3 drop-down-menu
现在我已经尝试解决这个问题几个小时了,我即将放弃......
我正在使用Telerik的MVC 3网格控制器.在我的网格中,我希望下拉列表选择的项目对应于用户的角色.下拉列表具有所有用户角色.
@(Html.Telerik().Grid(Model)
.Name("Grid").TableHtmlAttributes(new { width="800"})
.Columns(columns =>
{
//if (userIsInWhateverRole){
// columns.Template(o => Html.Action(GenerateYourLinkStuffHere));
//}
columns.Bound(o => o.Name).Width(150);
columns.Bound(o => o.Email).Width(120);
columns.Template(
@<text>
@Html.DropDownList(item.Role, (IEnumerable<SelectListItem>)item.Roles)
@Html.DropDownListFor(x => item.Role, (IEnumerable<SelectListItem>)item.Roles)
</text>
).Width(120);
})
.Sortable()
.Scrollable()
.Groupable()
.Filterable()
.Pageable(paging => paging.PageSize(5))
)
Run Code Online (Sandbox Code Playgroud)
你应该尝试这样的事情
在你的模型中,[UIHint("Role")]
为Role属性添加一个属性(保持简单的字符串)
按原样加载网格
columns.Bound(o => o.Name).Width(150);
columns.Bound(o => o.Email).Width(120);
columns.Bound(o => o.Roll).Width(120);
Run Code Online (Sandbox Code Playgroud)
添加一个名为Role.cshtml
EditorTemplates 的视图(this is a folder, directory like as View/(controller-specific-folder)/EditorTemplates)
,最后将您的下拉列表放在Role.cshtml
视图中.
有关详细信息,请访问http://www.telerik.com/community/forums/aspnet-mvc/grid/combo-box-in-grid.aspx 示例http://www.telerik.com/ClientsFiles/327900_TelerikMvcGridEditingDropdown.zip