本文介绍了为什么ASP.NET MVC 5的kendo ui示例的DropDown列表模板运行不正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Kendo ui Grid使用下拉模板.此示例用于ASP.NET MVC但是当单击下拉列表时,它将显示不是下拉列表的ID和名称.我复制并替换了代码,但没有显示ID输入和Name输入的下拉菜单.这个例子的链接是: https://demos.telerik.com/aspnet-mvc/grid/editing-自定义

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

我的edit_custom.cshtml:

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"))
  )
 )

和我的ClintCategory.cshtml:

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"])
   )

这是我最终视图的图像: https://imgur.com/a/5gVX6f2

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

预先感谢

推荐答案

1-在视图/共享/EditTemplates中创建一个文件夹,并将其名称更改为EditTemplates2将ClintCategory.cshtml复制到EditTemplates中3-添加EditorTemplateName("ClintCategory")
columns.Bound(p => p.Category).ClientTemplate("#=Category.CategoryName#").EditorTemplateName("ClintCategory").Width(180)

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)

并更改ClintCategory.cshtml

and change ClintCategory.cshtml

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

)

运行并享受:)

这篇关于为什么ASP.NET MVC 5的kendo ui示例的DropDown列表模板运行不正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 06:35