Custom Error message with HTTPStatusCodeResult & j

2019-02-09 12:02发布

I have a controller action that returns some JSON results to the jQuery Full Calendar plugin. I return a HTTPStatusCodeResult with a custom error message if there was an error, But I can't get the custom error message to display. All that's is displayed in the alert box is the default Http status (ie: 'Forbidden', or 'Internal Server Error')

Controller code that returns the error messages

else if(id != CurrentUser.UserId)
{
    return new HttpStatusCodeResult(403, "You are not authorised to view this.");
}
else
{
    return new HttpStatusCodeResult(500, "There was an error on the server.");
}

jQuery code

$(document).ready(function () {
             $('#calendar').fullCalendar({
                 header: {
                     left: 'prev,next today',
                     center: 'title',
                     right: 'month,agendaWeek,agendaDay'
                 },
                 height: 600,
                 eventSources: [{
                     url: events,
                     type: 'Get',
                     error: function(response, status, error) {
                         alert(response.statusText);
                     }
                 }],
                 allDayDefault: false,
                 selectable: true,
                 eventClick: function (event) {
                     if (event.url) {
                         $('#details').load(event.url);
                     }
                 },

1条回答
看我几分像从前
2楼-- · 2019-02-09 12:57

Actually there wasn't any problem in the code at all. The problem was with the ASP.NET development Web Server in Visual Studio. I switched to using IIS express and it works fine.

查看更多
登录 后发表回答