Reputation: 1887
While working with the Kendo UI Grid for ASP.NET MVC I am finding some frustrating behavior that I can't seem to understand or find any information on. I have a grid which makes a kendoGrid.saveChanges()
request to the server which has some server side validation. If the server-side validation fails, it returns the following result:
Response.StatusCode = HTTP_BAD_CLIENT_REQUEST; // const int 400
return PartialView("Error/BadRequest");
The partial view just has some basic HTML for displaying the error information to the user, and the grid's datasource error callback does the following:
function errorCallback(e) {
// Handles explicit Ajax and Kendo DataSource error callbacks
var content = e.responseText || e.xhr.responseText;
// Wrapper around a kendo.ui.Window to display content
Core.Alert.raiseAlert(content);
}
When I run my project in debug mode, or publish the Release version of the project to my local machine the e.xhr.responseText
value is populated correctly i.e. it contains the partial view's HTML message. However, as soon as I move this to the production server the e.xhr.responseText
simply contains the value "Bad Request"
which is also the HTTP status code I am currently using. I've tried using other status codes but the result is the same (error name is used as the responseText).
The reason I find this to be so odd is that I am doing something similar in another project for an internal application at our company and this works perfectly fine. They are running on the same versions and tools of both Kendo and ASP.NET.
Can anyone point me in the direct of tools or documentation, Kendo or AJAX, which explain why the response text is not using my partial view result or how I can map the partial view result I am sending to the xhr.responseText
property?
Edit: With trying different error codes, I found that certain status codes such 405 (Not Allowed) resulted in the IIS server error html being returned. So now I'm really stumped, why is it that some status codes simply return a name of the request, while others return templated HTML for that error code when I am specifying the return value and view to return?
Upvotes: 2
Views: 883
Reputation: 1887
Credit for findings and solutions goes to this post.
After doing some digging, I figured out that the issue came down to IIS overriding the content (and therefore partial view) being sent when I used the error HTTP status codes.
The solution is to add an <httpErrors>
tag to the system.webServer
in the web.config. I found that the following was sufficient to get my partial views to reach the client.
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
Upvotes: 3