Answer the question
In order to leave comments, you need to log in
How to determine that I'm on the main page?
I need to determine that I'm on the main page, and only display a certain class for it. I'm trying to do this
<main class="stretch-middle site-body @(Request.Url.AbsoluteUri.Contains("/") ? "" : "container")">
Answer the question
In order to leave comments, you need to log in
Decision
<main class="stretch-middle site-body @(Request.RawUrl == "/" ? "" : "container") ">
Place the script on the main page (cshtml) (example with JQuery):
$( document ).ready(function() {
$('main').addClass("container");
});
AbsoluteUri is "http://example.com/path?query#hash"
Of course, any absolute address will be Contains("/").
viktorulyushev , you must specify the main page in the App_Start/RouteConfig.cs file and, based on this, place the desired block on the corresponding View.
If you bind to what is contained in Url and define any conditions in _layoute, then remember that you can go to the main page not through a slash, but for example like this "home/index", and your script will not work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question