سؤال

HtML section in _Layout.cshtml

<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>

Html section in Index.cshtml

@{
   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>

Using bellow code I able to Replace !(IMAGEPATH)! only in _Layout.cshtml

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

But above described code not affecting child pages like Index.cshtml. Please tell me any event in ASP.NET MVC3 like old protected override void OnPreInit(EventArgs e) of Classic ASP.NET !!!!

I want to know which event effecting all the child pages before rendering in MVC3 ?

هل كانت مفيدة؟

المحلول

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);
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top