0

I'm using MVC4 with C# and I have a shared _Layout view that has a link to the home page, "index" via the "homeController".

   <p class="site-title"> 
@if (controller = Roles) {  
<a href="~/Roles/Index/" id="logo-holder">
 } else {
         <a href="~/Home/Index/" id="logo-holder">} 
         <img class="navbar-header" alt="logo" 
         src="~/Images/Comtrex_Logo_Blue_&_Orange.png" height="60" 
         width="302">
         <span style="padding-top:2em">Cloud Reporting</span>
         </a>
    </p>

How can I add and if else statement to navigate to different links depending on the view that the user is currently on?

  • The answers given here might help you do this: https://stackoverflow.com/q/28259739/1220550 or https://stackoverflow.com/q/13829648/1220550 – Peter B Mar 07 '19 at 14:24
  • thank you @PeterB that solved the problem. For anyone else I just did – Megan Meluskey Mar 07 '19 at 14:53
  • @if (ViewContext.RouteData.Values["Controller"].ToString() == "Roles") { my link then } else {my other link} – Megan Meluskey Mar 07 '19 at 14:54
  • Possible duplicate of [How do I hide an element in the shared layout based on the controller in MVC](https://stackoverflow.com/questions/28259739/how-do-i-hide-an-element-in-the-shared-layout-based-on-the-controller-in-mvc) – Peter B Mar 07 '19 at 14:58

0 Answers0