git checkout remotes/origin/cm-13.0-caf-8916
c.Status是一个可以为空的int?
如果我注释掉[ClientTemplate],我会看到状态值的正确int表示。但是,如果我使用客户端模板 - 它始终显示“打开”状态。
@(Html.Kendo().Grid()
......
......
.columns.Bound(c => c.Status).EditorTemplateName("_WorkStatusDropDown")
**.ClientTemplate("# if (1) { #" + "Open" + "# } else if (2) { #" + "Closed" + "# } else {#" + "In Progress" + "# } #");**
非常感谢任何帮助。
答案 0 :(得分:1)
请尝试使用以下代码段。
查看强>
<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>
<强> CONTROLLER 强>
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));
}
<强> MODEL 强>
public class Student
{
public int StudentID { get; set; }
public string StudentName { get; set; }
public int Status { get; set; }
}
如果有任何疑虑,请告诉我。