Why The DropDown list template of kendo ui sample for ASP.NET MVC 5 dont run right?

拥有回忆 提交于 2019-12-11 07:51:01

问题


I use dropdown template for kendo ui Grid.this example was for ASP.NET MVC but when click on the dropdown, it display ID and Name that is not dropdown. I copied and replaced the code but instead of dropdown that display Id input and Name input. the link of this example is: https://demos.telerik.com/aspnet-mvc/grid/editing-custom

my editing_custom.cshtml:

 @using Microsoft.AspNet.Identity.EntityFramework;
 @using UserManagerSample.KendoDropDown.KendoDropViewModel;
 @using Kendo.Mvc.UI


 <script 
    src="http://cdn.kendostatic.com/2013.3.1119/js/kendo.aspnetmvc.min.js"> 
  </script>
      @(Html.Kendo().Grid<ProductViewModel>()
    .Name("grid")
   .Columns(columns =>
    {
    columns.Bound(p => p.ProductName);
    columns.Bound(p => 
    p.Category).ClientTemplate("#=Category.CategoryName#").Width(180);
    columns.Bound(p => p.UnitPrice).Width(130);
    columns.Command(command => command.Destroy()).Width(150);
  })
.ToolBar(toolBar =>
{
    toolBar.Create();
    toolBar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))

.Pageable()
.Sortable()
.Scrollable()
.HtmlAttributes(new { style = "height:550px;" })
.DataSource(dataSource => dataSource
    .Ajax()
    .Batch(true)
    .ServerOperation(false)
    .Events(events => events.Error("error_handler"))
    .Model(model =>
    {
        model.Id(p => p.ProductID);
        model.Field(p => p.ProductID).Editable(false);
        model.Field(p => p.Category).DefaultValue(
            ViewData["defaultCategory"] as CategoryViewModel);
    })
    .PageSize(20)
    .Read(read => read.Action("EditingCustom_Read", "Grid"))
    .Create(create => create.Action("EditingCustom_Create", "Grid"))
    .Update(update => update.Action("EditingCustom_Update", "Grid"))
    .Destroy(destroy => destroy.Action("EditingCustom_Destroy", "Grid"))
  )
 )

and my ClintCategory.cshtml:

  @using UserManagerSample.KendoDropDown.KendoDropViewModel;
  @using Kendo.Mvc.UI;
 @model CategoryViewModel


    @(Html.Kendo().DropDownListFor(m => m)
    .DataValueField("CategoryID")
    .DataTextField("CategoryName")
    .BindTo((System.Collections.IEnumerable)ViewData["categories"])
   )

this is the image of my final view: https://imgur.com/a/5gVX6f2

Thanks in advance


回答1:


1-Create a folder in the view/shared/EditTemplates and change its name to EditTemplates 2-Copy the ClintCategory.cshtml in to the EditTemplates 3-Add EditorTemplateName("ClintCategory")
columns.Bound(p => p.Category).ClientTemplate("#=Category.CategoryName#").EditorTemplateName("ClintCategory").Width(180)

and change ClintCategory.cshtml

@(Html.Kendo().DropDownListFor(m => m.CategoryName)
    .DataValueField("CategoryID")
    .DataTextField("CategoryName")
    .BindTo((System.Collections.IEnumerable)ViewData["categories"])

)

Run And Enjoy:)



来源:https://stackoverflow.com/questions/54136786/why-the-dropdown-list-template-of-kendo-ui-sample-for-asp-net-mvc-5-dont-run-rig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!