How to check IF is page (home, blog) etc?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Hi,

I have this code with a iframe video.


<div class="gsvideo" id="header-video">
  <div class="gsvideo__modal">
    <div class="modal">
      <div class="modal__close"><span class="gs-icon-delete"></span></div>
        <div class="gsvideo__iframe">
          @Html.Action("TopicBlock", "Topic", new { systemName = "home-header-video" })
        </div>
       </div>
      </div>
     <div class="gsvideo__overlay"></div>
</div>


How can i show this video only if it is a specific page?

Thanks
6 years ago
Galanthus wrote:
Hi,

I have this code with a iframe video.


<div class="gsvideo" id="header-video">
  <div class="gsvideo__modal">
    <div class="modal">
      <div class="modal__close"><span class="gs-icon-delete"></span></div>
        <div class="gsvideo__iframe">
          @Html.Action("TopicBlock", "Topic", new { systemName = "home-header-video" })
        </div>
       </div>
      </div>
     <div class="gsvideo__overlay"></div>
</div>


How can i show this video only if it is a specific page?

Thanks


For Home Page ===> Try something like bellow

@{
    bool homePage=false;
    if (Url.ActionContext.RouteData.Values["controller"].ToString().Equals("home", StringComparison.InvariantCultureIgnoreCase) &&
        Url.ActionContext.RouteData.Values["action"].ToString().Equals("index", StringComparison.InvariantCultureIgnoreCase))
    {
      homePage=true ;
    }
}

@if(homePage){

//do what you want
}
6 years ago
Doesn't work:



Compiler Error Message: CS1061: 'System.Web.Mvc.UrlHelper' does not contain a definition for 'ActionContext' and no extension method 'ActionContext' accepting a first argument of type 'System.Web.Mvc.UrlHelper' could be found (are you missing a using directive or an assembly reference?)

Source Error:


Line 1:  @{
Line 2:      bool homePage=false;
Line 3:      if (Url.ActionContext.RouteData.Values["controller"].ToString().Equals("home", StringComparison.InvariantCultureIgnoreCase) &&
Line 4:          Url.ActionContext.RouteData.Values["action"].ToString().Equals("index", StringComparison.InvariantCultureIgnoreCase))
Line 5:      {


ALso, how can do the same for blog, news etc.
6 years ago
Galanthus wrote:
Hi,

I have this code with a iframe video.


<div class="gsvideo" id="header-video">
  <div class="gsvideo__modal">
    <div class="modal">
      <div class="modal__close"><span class="gs-icon-delete"></span></div>
        <div class="gsvideo__iframe">
          @Html.Action("TopicBlock", "Topic", new { systemName = "home-header-video" })
        </div>
       </div>
      </div>
     <div class="gsvideo__overlay"></div>
</div>


How can i show this video only if it is a specific page?

Thanks



Setup a class for a div you want, say active/inactive. In your css file:
.active { display: block; }
.inactive { display:none; }

and you can use cheeky quick javascript to simply edit the class of the container depending on whatever condition you want

if ( your condition ){
$('.modal').removeClass("inactive").addClass("active");
}
if ( opposite condition ){
$('.modal').removeClass("active").addClass("inactive");

}

For example. When you're working with looks, making something visible/invisible, css classes are your best friend, 99% of cases :) imo
6 years ago
Galanthus wrote:
Doesn't work:



Compiler Error Message: CS1061: 'System.Web.Mvc.UrlHelper' does not contain a definition for 'ActionContext' and no extension method 'ActionContext' accepting a first argument of type 'System.Web.Mvc.UrlHelper' could be found (are you missing a using directive or an assembly reference?)

Source Error:


Line 1:  @{
Line 2:      bool homePage=false;
Line 3:      if (Url.ActionContext.RouteData.Values["controller"].ToString().Equals("home", StringComparison.InvariantCultureIgnoreCase) &&
Line 4:          Url.ActionContext.RouteData.Values["action"].ToString().Equals("index", StringComparison.InvariantCultureIgnoreCase))
Line 5:      {


ALso, how can do the same for blog, news etc.


If 3.90 or lower then try ==> For Blog List page

@{

if (Url.RequestContext.RouteData.Values["controller"].ToString().Equals("blog", StringComparison.InvariantCultureIgnoreCase) &&
        Url.RequestContext.RouteData.Values["action"].ToString().Equals("list", StringComparison.InvariantCultureIgnoreCase))
    {
        //do something what you want;
    }
}

For Home Page ==>

@{

if (Url.RequestContext.RouteData.Values["controller"].ToString().Equals("home", StringComparison.InvariantCultureIgnoreCase) &&
        Url.RequestContext.RouteData.Values["action"].ToString().Equals("index", StringComparison.InvariantCultureIgnoreCase))
    {
        //do something what you want;
    }
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.