2014-09-22 131 views
2

如何編寫asp.net mvc的預渲染事件? 其實我的問題是,我需要將我的網頁在IE10中的文檔標準設置爲IE9 +標準,因爲默認情況下它是IE7 +標準,而且由於這個問題,我的應用程序無法按照要求工作。在ASP.net中佈局頁面的預渲染事件MVC

回答

1

如何編寫asp.net mvc的預渲染事件?

您可以創建一個簡單的ActionFilter - Reference taken from here

public class UpdateFilter : ActionFilterAttribute 
    { 
     private HtmlTextWriter tw; 
     private StringWriter sw; 
     private StringBuilder sb; 
     private HttpWriter output; 

     public override void OnActionExecuting(ActionExecutingContext filterContext) 
     { 
      sb = new StringBuilder(); 
      sw = new StringWriter(sb); 
      tw = new HtmlTextWriter(sw); 
      output = (HttpWriter)filterContext.RequestContext.HttpContext.Response.Output; 
      filterContext.RequestContext.HttpContext.Response.Output = tw; 
     } 

     public override void OnResultExecuted(ResultExecutedContext filterContext) 
     { 
      string response = sb.ToString(); 
      output.Write(response); 
     } 
    } 

當你請求一個頁面,你可以在OnResultExecuted()自定義HTML的響應。當你把一個斷點,它會是這樣 -

enter image description here