验证在kendo网格批量编辑中不起作用

时间:2015-01-17 11:38:57

标签: asp.net-mvc asp.net-mvc-4 kendo-ui kendo-grid kendo-asp.net-mvc

您好我使用kendo下拉作为网格中的编辑器模板它工作正常但如果没有从下拉列表中选择任何值,我点击添加新的然后它不会在网格中显示错误并添加网格的新行...我的验证不起作用

这是我的网格代码:

 @(Html.Kendo().Grid(Model.PrevilegeViewModels)
              .Name("PrevilegeViewModels")
              .ToolBar(tools => tools.Create().Text("Add new product"))
              .Editable(editable => editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Bottom))
              .Columns(columns =>
              {
                  columns.Bound(p => p.Table_ID).ClientTemplate("#= Table_ID #" +
                  "<input type='hidden' name='PrevilegeViewModels[#= index(data)#].Table_ID' value='#= Table_ID #' />"
                  ).EditorTemplateName("Table").Title("Table").Width(300);

                columns.Bound(p => p.P_Add).Title("ADD").ClientTemplate("#= P_Add #" +
                    "<input type='hidden' name='PrevilegeViewModels[#= index(data)#].P_Add' value='#= P_Add #' />"
                  ).Width(150);
                  columns.Bound(p => p.P_Delete).Title("DELETE").ClientTemplate("#= P_Delete #" +
                    "<input type='hidden' name='PrevilegeViewModels[#= index(data)#].P_Delete' value='#= P_Delete #' />"
                  ).Width(150);
                  columns.Bound(p => p.P_Edit).Title("EDIT").ClientTemplate("#= P_Edit #" +
                    "<input type='hidden' name='PrevilegeViewModels[#= index(data)#].P_Edit' value='#= P_Edit #' />"
                  ).Width(150);
                  columns.Command(command => command.Destroy()).Width(100);
              })
              .DataSource(dataSource => dataSource.Ajax()
                   .Model(model =>
                   {
                       model.Id(p => p.Previleges_ID);
                       model.Field(p => p.Previleges_ID).Editable(false);
                   })
                   .ServerOperation(false)
              )
        )

这是我的编辑模板(下拉列表)

@using System.Collections

@model System.Int32
@(Html.Kendo().DropDownList()
          .Name("Table_ID")
          .OptionLabel("---Select---")
          .DataTextField("TableName")
          .DataValueField("ID")
          .HtmlAttributes(new { style = "width:300px" })
          .Filter(FilterType.StartsWith)
          .DataSource(source =>
          {
              source.Read(read =>
              {
                  read.Action("GetTable", "Privilege");
              })
              .ServerFiltering(true);
          })

那是我的模特

public class PrevilegeViewModel
    {
        [Key]
        public int Previleges_ID { get; set; }
        [Required]
        [Range(1,UInt32.MaxValue)]
        public int Table_ID { get; set; }
        [Required]
        public bool P_Add { get; set; }
        [Required]
        public bool P_Edit { get; set; }
        [Required]
        public bool P_Delete { get; set; }        
    }

我希望如果我在下拉菜单中没有选择任何值,它就不会为零并且不会添加新行...提供验证错误。

我还附上了UI图片。请指导我......!

enter image description here

0 个答案:

没有答案