• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 704
  • Last Modified:

Hide a tab in MVC

I just created a vanilla "MVC 3" application in VS 2010.

How can I hide the "Home" tab programmatically when the "view" loads?
0
Tom Knowlton
Asked:
Tom Knowlton
2 Solutions
 
ambienceCommented:
By default the Home tab is in the _Layout.cshtml in the Shared views folder. One possible way to hide it is shown below.

            <div id="logindisplay">
                @Html.Partial("_LogOnPartial", Session["user"])
            </div>
            <ul id="menu">
@if (Session["EnableHomeTab"] != null)
{
               <li>@Html.ActionLink("Home", "Index", "Home")</li>
}
               <li>@Html.ActionLink("File Browser", "Index", "FileBrowser")</li>
                <li>@Html.ActionLink("Settings", "Index", "Settings")</li>
            </ul>

Then whenever you want to enable Home tab just add a key "EnableHomeTab" to session object

Session["EnableHomeTab"] = true;

to disable it again

Session.Remove("EnableHomeTab");
0
 
Bob LearnedCommented:
Tom,

If you aren't familiar with MVC 3 yet, I would assume that you are using the Razor view engine, rather than the ASP.NET view engine, as that wonderful example above is Razor syntax.

Bob
0
 
Tom KnowltonWeb developerAuthor Commented:
Thank you!

Tom

I did pick "Razor" when creating the project.  I'll have to read more about "Razor" online.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now