2015-07-03 55 views
0

处理ASP.Net Web窗体混合的项目& MVC。自定义错误消息MVC

场景:在Web窗体应用程序中,页面的一部分使用MVC Partial View进行渲染,如下图所示。

enter image description here

在Web窗体ASPX页面,定义了一个事业部与ID = MVCPartialView1和使用jQuery阿贾克斯成功可以绑定返回管窥到Web窗体。

$.ajax(
{ 
success: function (msg) { $("#MVCPartialView1").html(msg); } 
}); 

对于处理错误使用以下代码的场景。

[AttributeUsage(AttributeTargets.Class)] 
    public sealed class ErrorAttribute : HandleErrorAttribute 
    { 
     public override void OnException(ExceptionContext filterContext) 
     { 
      // Execute the normal exception handling routine 
      base.OnException(filterContext); 

      if (filterContext.HttpContext.Request.IsAjaxRequest()) 
      { 
       filterContext.Result = new ViewResult 
       { 
        ViewName = "CustomError.aspx" 
       }; 
      } 
     } 
    } 

基本控制器:

[ErrorAttribute] 
public class BaseController : Controller 

实际的问题是当任何异常中的MVC局部视图(控制器)发生,CustomError只显示内部DIV MVCPartialView1但它将使感展现CustomError为全含的WebForm.aspx

enter image description here

但是电动xpected CustomError消息是:

enter image description here

+0

你为什么混合MVC和Web窗体?出于好奇。 – Derek

+0

这是一个已经存在于Web窗体中的现有项目。慢慢地,我们正在向MVC迁移 – Vinod

回答

0

你可以把它只有在你的情况下JS工作。

有些事情是这样的:

$.ajax(
{ 
    success: function (msg) 
    { 
     if(msg.indexOf("Error") > -1) //You should check if Error page returned 
     { 
     window.location.href = "CustomError.aspx"; //Here if redirect to error of full page 
     } 
     else 
     { 
     $("#MVCPartialView1").html(msg); 
     } 
    } 
}); 
+0

是的,我猜这是做它的唯一方法。 – Vinod