I haven't been able to find an example of Kendo + MVC Web API where post/update methods return validation errors. It doesn't look like there is a Kendo extension that could make the following code work.
public HttpResponseMessage Post([ModelBinder(typeof(Prototype.WebApi.ModelBinders.DataSourceRequestModelBinder))][DataSourceRequest] DataSourceRequest request, User user)
{
if (this.ModelState.IsValid)
{
//save
}
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState.ToDataSourceResult());
}
becaue ModelState in this context is System.Web.Http.ModelBinding.ModelStateDictionary and Kendo extensions expect System.Web.Mvc.ModelStateDictionary.
So what is the best way to return ModelState errors from Web API to Kendo?
This works fantastic for us, though we never see ModelState errors and usually omit that part...
Kendo Grid
Controller
UPDATED Controller
We have found this flow to work a bit better and it adds error logging to Elmah (generic example)...
Common JavaScript and Kendo Window
Bonus
Our BaseModel also has an ErrorMessage parameter that we put other types of errors into that checks on page load if the same alert window should be opened for anything else.
This has a very nice presentation when an error is thrown - keeps our in-house users from freaking out. I hope this helps you out.