Following is my kendo grid
@section scripts{
@Scripts.Render("~/bundles/jqueryval")
}
@(Html.Kendo().Grid<Category>()
.Name("grid")
.Columns(columns =>
{ columns.Bound(c => c.Id);
columns.Bound(c => c.Name)
.ClientTemplate("<a href='" + Url.Action("Edit", "category") + "/#= Id #' " + ">#= Name #</a>").Width(140)
.Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(true)));
columns.Bound(c => c.Color).Width(80).Filterable(false).Sortable(false).ClientTemplate("<div style='width: 25px; height: 25px; background: #=Color#;'></div>");
columns.Bound(r => r.AltName).Width(240);
columns.Command(command => { command.Edit(); }).Width(150);
})
.Events(e => e.Edit("grid_edit"))
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.EnableCustomBinding(true)
.HtmlAttributes(new { style = "height: 380px;" })
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.Scrollable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax().Read(read => read.Action("Get", "Person"))
.Update(update => update.Action("SaveOrUpdate", "Person"))
.Create(update => update.Action("SaveOrUpdate", "Person"))
.Model(model =>
{
model.Id(p => p.Id);
model.Field(p => p.Color).DefaultValue("#000000");
model.Field(p => p.Id).DefaultValue(new Guid());
model.Field(p => p.TenantId).DefaultValue(new Guid());
model.Field(p => p.RowVersion);
})
)
)
Following is my viewmodel
public class Person
{
[Required]
[Remote("IsPersonUnique", "Validation", "Admin" , AdditionalFields = "Id")]
public string Name { get; set; }
[UIHint("CategoryColorPicker")]
public string Color { get; set; }
public string AltName { get; set; }
}
And my remote validation action method
public JsonResult IsPersonUnique(string name, Guid id)
{
return CategoryService.IsPersonUnique(name, id)
? Json(true, JsonRequestBehavior.AllowGet)
: Json(false, JsonRequestBehavior.AllowGet);
}
Now the remote validation doesn't fire when I am adding items inline in grid.
But it works fine when I add it through another detail page, for the same model.
But the required field validations work fine.
@section scripts{
@Scripts.Render("~/bundles/jqueryval")
}
@(Html.Kendo().Grid<Category>()
.Name("grid")
.Columns(columns =>
{ columns.Bound(c => c.Id);
columns.Bound(c => c.Name)
.ClientTemplate("<a href='" + Url.Action("Edit", "category") + "/#= Id #' " + ">#= Name #</a>").Width(140)
.Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(true)));
columns.Bound(c => c.Color).Width(80).Filterable(false).Sortable(false).ClientTemplate("<div style='width: 25px; height: 25px; background: #=Color#;'></div>");
columns.Bound(r => r.AltName).Width(240);
columns.Command(command => { command.Edit(); }).Width(150);
})
.Events(e => e.Edit("grid_edit"))
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.EnableCustomBinding(true)
.HtmlAttributes(new { style = "height: 380px;" })
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.Scrollable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax().Read(read => read.Action("Get", "Person"))
.Update(update => update.Action("SaveOrUpdate", "Person"))
.Create(update => update.Action("SaveOrUpdate", "Person"))
.Model(model =>
{
model.Id(p => p.Id);
model.Field(p => p.Color).DefaultValue("#000000");
model.Field(p => p.Id).DefaultValue(new Guid());
model.Field(p => p.TenantId).DefaultValue(new Guid());
model.Field(p => p.RowVersion);
})
)
)
Following is my viewmodel
public class Person
{
[Required]
[Remote("IsPersonUnique", "Validation", "Admin" , AdditionalFields = "Id")]
public string Name { get; set; }
[UIHint("CategoryColorPicker")]
public string Color { get; set; }
public string AltName { get; set; }
}
And my remote validation action method
public JsonResult IsPersonUnique(string name, Guid id)
{
return CategoryService.IsPersonUnique(name, id)
? Json(true, JsonRequestBehavior.AllowGet)
: Json(false, JsonRequestBehavior.AllowGet);
}
Now the remote validation doesn't fire when I am adding items inline in grid.
But it works fine when I add it through another detail page, for the same model.
But the required field validations work fine.