chiapa
chiapa

Reputation: 4412

Show/hide item in "_layout"

I'm working on a C# MVC project and I want a master page that has a header that contains some information among which is the application logo on the top left corner. However, there's one view in which I don't want it to be seen, the login page.

So, how can I hide it for just the Home/Index view and then display it for all the other views?

Here's part of the _Layout.cshtml

...
   <body>
        <header>

            <div class="content-wrapper">

                <div class="float-left">
                    <a href="../Home/Index"><img src="../../Images/_logo.png" alt="whatever" /></a>
                </div>
...

This shows in every page, I just wish I could hide it from the initial page where the user enters its credentials.

How can this be achieved?

Thanks

Upvotes: 1

Views: 3625

Answers (6)

Friyank
Friyank

Reputation: 479

use script

 $(window).load(function () {
     $("#actionlinkid").hide = true;
});

Upvotes: 0

Anil Soman
Anil Soman

Reputation: 2467

You can write a JQuery on your login page (cshtml). Use $(document).ready() event and hide the div containing the logo image.

Upvotes: 0

brainless coder
brainless coder

Reputation: 6430

You can use section of MVC views for this purpose. They are precisely used for this -

in _layout.cshtml include header section as this, so that the header is included as an optinal section

 @RenderSection("Header", False)
 @RenderSection("MainContent")

then other pages you can have separate header such as this (some.cshtml) -

@section Header {
    <header>
            <div class="content-wrapper">
                <div class="float-left">
                    <a href="../Home/Index"><img src="../../Images/_logo.png" alt="whatever" /></a>
                </div>
}

@section MainContent{
     other body content.
}

And for login just don't define the section and only provide the body -

 @section MainContent{
     other body content.
}

This gives you not only the option to show hide header but also a great option to customize your layout based on the contents and need of the content pages.

You can learn more from here -

http://www.codeproject.com/Articles/383145/RenderBody-RenderPage-and-RenderSection-methods-in

and in msdn you can find the Documentation

http://msdn.microsoft.com/en-us/library/system.web.webpages.webpagebase_methods(v=vs.111).aspx

Upvotes: 3

ashish
ashish

Reputation: 245

Agree with solution given by Softsen. But in case you are asking only for hiding logo for particular page, You can do it as below:

  @if(Request.Url.ToString().IndexOf("index")==-1)
            {
            <div class="float-left">
                <p class="site-title">@Html.ActionLink("your logo here", "Index", "Home")</p>
            </div>
            }

Upvotes: -1

user32826
user32826

Reputation:

You can check to see if the current user is authenticated, and if not then hide the elements you wish to hide.

@if(HttpContext.Current.User != null && HttpContext.Current.User.Identity != null && HttpContext.Current.User.Identity.IsAuthenticated) 
{
    ... stuff to show if user is authenticated here ...
}

Upvotes: 0

SoftSan
SoftSan

Reputation: 2472

You can set Layout = null for that Login page.

@{
    Layout = null;
}

Upvotes: 4

Related Questions