V
V
viktorulyushev2018-03-16 08:53:31
ASP.NET
viktorulyushev, 2018-03-16 08:53:31

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

But it doesn't work, it's always true. How can I determine that there is nothing after the slash?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
viktorulyushev, 2018-03-16
@viktorulyushev

Decision

<main class="stretch-middle site-body @(Request.RawUrl == "/" ? "" : "container") ">

C
cicatrix, 2018-03-16
@cicatrix

Place the script on the main page (cshtml) (example with JQuery):

$( document ).ready(function() {
    $('main').addClass("container");
});

A
Alexander Yudakov, 2018-03-16
@AlexanderYudakov

AbsoluteUri is "http://example.com/path?query#hash"
Of course, any absolute address will be Contains("/").

M
mindgrow, 2018-03-16
@mindgrow

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 question

Ask a Question

731 491 924 answers to any question