c# – 使用HTTPStatusCodeResult和jQuery的自定义错误消息
发布时间:2020-12-15 08:09:47 所属栏目:百科 来源:网络整理
导读:我有一个控制器动作,它将一些 JSON结果返回给jQuery Full Calendar插件.如果出现错误,我返回带有自定义错误消息的HTTPStatusCodeResult,但是我无法显示自定义错误消息.警报框中显示的所有内容都是默认的Http状态(即:’Forbidden’或’Internal Server Error
我有一个控制器动作,它将一些
JSON结果返回给jQuery Full Calendar插件.如果出现错误,我返回带有自定义错误消息的HTTPStatusCodeResult,但是我无法显示自定义错误消息.警报框中显示的所有内容都是默认的Http状态(即:’Forbidden’或’Internal Server Error’)
返回错误消息的控制器代码 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代码 $(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); } }, 解决方法
实际上代码中没有任何问题.问题出在Visual Studio中的ASP.NET开发Web服务器上.我转而使用IIS express,它运行正常.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |