c# - dropdownlist in kendo grid not working -
im trying use incell editing , use of http://demos.telerik.com/aspnet-mvc/grid/editing-custom can't find partial view dropdownlist should rendered from.
partial view (testview.cshtml)
@using kendo.mvc.ui @(html.kendo().dropdownlist() .name("resourcetype") // name of widget should same name of property .datavaluefield("id") // value of dropdown taken employeeid property .datatextfield("name") // text of items taken employeename property .bindto((system.collections.ienumerable)viewdata["defaultresourcetype"]) // list of employees populated in controller
)
this grid:
@(html.kendo().grid<rms.admin.viewmodel>() .name("resourcegrid") .columns(columns => { columns.bound(c => c.resourceid).hidden(); columns.bound(c => c.resourcename); columns.bound(c => c.descritption); columns.bound(c => c.resourcetype.name).clienttemplate("#=resourcetype.name#"); columns.bound(c => c.approved); columns.bound(c => c.isenabled); columns.command(command => { command.edit(); command.destroy(); }).width(172).title("edit/delete"); }) .toolbar(toolbar => toolbar.create()) .editable(editable => editable.mode(grideditmode.incell)) .scrollable() .sortable() .pageable(pageable => pageable .refresh(true) .pagesizes(true) .buttoncount(5)) .datasource(datasource => datasource .ajax() .model(model => { model.id(s => s.resourceid); model.field(s => s.resourcetype).defaultvalue(viewdata["defaultresourcetype"] rms.admin.viewmodel.resourcetypeid); }) .create(update => update.action("createresource", "home")) .read(read => read.action("readresource", "home")) .update(update => update.action("savesystem", "home")) .destroy(destroy => destroy.action("removesystem", "home")) )
)
here part of model:
public string resourceuserid { get; set; } [uihint("testview")] public resourcetypeid resourcetype { get; set; }
this in controller bind data:
private void getresourcetypeid() { //string [] list = new string[]{"image", "document", "other"}; ilist<viewmodel.resourcetypeid> list = new list<viewmodel.resourcetypeid>(); var = new viewmodel.resourcetypeid { name = "image", id = 1 }; var b = new viewmodel.resourcetypeid { name = "document", id = 2 }; var c = new viewmodel.resourcetypeid { name = "other", id = 3 }; list.add(a); list.add(b); list.add(c); viewdata["defaultresourcetype"] = list.first(); }
i error when trying render grid: resource looking (or 1 of dependencies) have been removed, had name changed, or temporarily unavailable. please review following url , make sure spelled correctly.
what missing?
first off trying bind 1 item viewdata["defaultresourcetype"] = list.first();
. instead should bind whole list , set default option .value("1")
has "images" default.
@(html.kendo().dropdownlist() .name("resourcetype") .datavaluefield("id") .datatextfield("name") .bindto((system.collections.ienumerable)viewdata["resourcetypelist"]) .value(viewdata["defaultresourcetype"]) );
also template column in mvc may want set editortemplatename
columns.bound(e => e.mycolumn).editortemplatename("dropdowntemplate")
and define template want use somewhere else on page.
<script id="dropdowntemplate" type="text/x-kendo-template"> @(html.kendo().dropdownlist() .name("mydropdown") ..... .toclienttemplate() ) </script>
if can declare stand alone template in /views/shared/ folder. not have add
.toclienttemplate()
or script tags. reference file name. use template on multiple pages in project.
Comments
Post a Comment