0

_Layout.cshtml 中的 HtML 部分

<div id="header">
      <div class="logo"><a href="#"><img src="@Url.Content("~/!(IMAGEPATH)!/logo.png")" alt="" /></a></div>
      <div class="fb_like"><img src="@Url.Content("~/!(IMAGEPATH)!/fb_like_btn.png")" alt="" /></div>
      <div class="google_plus"><img src="@Url.Content("~/!(IMAGEPATH)!/google_plus.png")" alt="" /></div>
      <div class="header_rt">
        <ul>
          <li>Call us: 1500 258 789</li>
          <li><a href="#">Live chat</a></li>
          <li><a href="#">My Account</a></li>
          <li><a href="#">Sign in</a></li>
        </ul>
        <div class="search">
          <input type="text" value="Type your keyword..." class="srh_txt" />
          <input name="Submit" type="submit" value="Submit" class="srh_btn" />
        </div>
      </div>
    </div>
  <div id="main">
      @RenderBody()
 </div>

Index.cshtml 中的 Html 部分

@{
   ViewBag.Title = "Home Page";
}
<div class="clr"></div>
<div id="banner">
<div id="slider"><img src="@Url.Content("~/!(IMAGEPATH)!/banner.jpg")" alt="" /></div>
<div class="banner_rt">
  <div class="adv1"><img src="@Url.Content("~/!(IMAGEPATH)!/adv1.jpg")" alt="" /></div>
  <div class="adv2"><img src="@Url.Content("~/!(IMAGEPATH)!/adv2.jpg")" alt="" /></div>
</div>

使用下面的代码我可以替换!(IMAGEPATH)!仅在 _Layout.cshtml 中

   void Application_PostReleaseRequestState(object sender,EventArgs e)
   {
      if(string.CompareOrdinal(Response.ContentType,"text/html") == 0)
      {
         Response.Filter = new ResponseFilter(Response.Filter);
      }
   }

但上述代码不会影响像Index.cshtml这样的子页面。请告诉我ASP.NET MVC3中的任何事件,例如 Classic ASP.NET 的旧受保护覆盖​​ void OnPreInit(EventArgs e)!!!

我想知道在 MVC3 中渲染之前哪个事件会影响所有子页面?

4

1 回答 1

0

Within Base Controller, write the bellow code

protected override void OnResultExecuting(ResultExecutingContext filterContext)
    {
        var response = filterContext.HttpContext.Response;
        if (string.CompareOrdinal(response.ContentType, "text/html") == 0)
        {
            response.Filter = new ResponseFilter(response.Filter);
        }
        base.OnResultExecuting(filterContext);
    }
于 2013-01-15T07:46:52.317 回答