【问题标题】:Kendo UI Gridview Column Client Template not workingKendo UI Gridview 列客户端模板不起作用
【发布时间】:2015-11-15 18:42:14
【问题描述】:
@(Html.Kendo().Grid()
 ......
 ......
  .columns.Bound(c => c.Status).EditorTemplateName("_WorkStatusDropDown")
**.ClientTemplate("# if (1) { #" + "Open" + "# }  else if (2) { #" + "Closed" + "# } else {#" + "In Progress" + "# } #");**

c.Status 是一个可为空的 int?

如果我注释掉 [ClientTemplate],我会看到状态值的正确 int 表示。但是,如果我使用客户端模板 - 它始终显示“打开”作为状态。

Status : 1 = Open, 2 = Closed, 3 = In Progress

非常感谢任何帮助。

【问题讨论】:

    标签: model-view-controller kendo-ui telerik kendo-grid telerik-grid


    【解决方案1】:

    请尝试以下代码 sn-p。

    查看

    <div>
        @(Html.Kendo().Grid<MvcApplication1.Models.Student>()
            .Name("grid")
            .Columns(columns =>
            {
                columns.Bound(c => c.StudentID);
                columns.Bound(c => c.StudentName);
                columns.Bound(c => c.Status).ClientTemplate("# if (Status == 1) { #" + "Open" + "# }  else if (Status == 2) { #" + "Closed" + "# } else {#" + "In Progress" + "# } #");
            })
            .DataSource(dataSource => dataSource
                .Ajax()
                .Read(read => read.Action("Grid_Read", "Home"))
            )
        )
    </div>
    

    控制器

    public ActionResult Grid_Read([DataSourceRequest] DataSourceRequest request)
    {
        List<Student> students = new List<Student>();
        students.Add(new Student() { Status = 1, StudentID = 1, StudentName = "a" });
        students.Add(new Student() { Status = 2, StudentID = 2, StudentName = "a" });
        students.Add(new Student() { Status = 3, StudentID = 3, StudentName = "c" });
    
        return Json(students.ToDataSourceResult(request));
    }
    

    型号

    public class Student
    {
        public int StudentID { get; set; }
        public string StudentName { get; set; }
        public int Status { get; set; }
    }
    

    如果有任何问题,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多