Telerik mesh with dropdownList

Now I tried to solve the problem in a few hours, and I'm going to refuse ...

I am using MVC 3 grid control from Telerik. In my grid, I want the selected dropdownlists to match the user role. The drop-down list contains all user roles.

@(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)) ) 
+4
source share
2 answers

you should try something like this

in your model add the [UIHint("Role")] attribute for the Role property (save it in a simple line)

load the grid as it is

 columns.Bound(o => o.Name).Width(150); columns.Bound(o => o.Email).Width(120); columns.Bound(o => o.Roll).Width(120); 

add a view called Role.cshtml inside EditorTemplates (this is a folder, directory like as View/(controller-specific-folder)/EditorTemplates) and finally place the drop-down menu in the Role.cshtml .

More details http://www.telerik.com/community/forums/aspnet-mvc/grid/combo-box-in-grid.aspx sample http://www.telerik.com/ClientsFiles/327900_TelerikMvcGridEditingDropdown.zip

+6
source

So instead

 @Html.DropDownListFor(x => item.Role, (IEnumerable<SelectListItem>)item.Roles) 

You have to do it

 @Html.DropDownListFor(x => item.Role, new SelectList(item.Roles, item.Role)) 

And that should solve your problem.

+1
source

Source: https://habr.com/ru/post/1393150/


All Articles