I have an MVC Razor app with the Kendo Grid using the popup editor modeled on the demo. The popup comes up OK, and the model is invoked and does it's validation steps. I do not use Entity Framework, the model has validation logic that applies business rules. My problem is that when validation fails, or succeeds for that matter, the demo does not show what to return to the view/grid. How are errors formatted for example?
My other question is what to return if successful? The object the controller got from the editor is a singular object, not IQueriable or IEnumerable. My grid is populated with data, and the model has already done the insert to the database if validation passed. Do I refresh the grid, and if so, how can I make sure the user is kept in the same section of the grid?
My controller code for Create is shown below (the return code shows an Intellisense error you can't see here):
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingPopup_Create([DataSourceRequest] DataSourceRequest request, BuyerAssignmentRecord bar)
{
if (bar != null)
{
if (bar.DepartmentOI == 0) { bar.DepartmentOI = -1; }
if (bar.EmployeeOI == 0) { bar.EmployeeOI = -1; }
if (bar.Validate())
{
bar.Create();
}
else
{
// todo: what to return if validation failed?
}
}
return Json(new[] { BuyerAssignmentRecord }.ToDataSourceResult(bar, ModelState));
}