Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes this seem like an alright approach to implementing tabs in ASP.NET MVC?
    primarykey
    data
    text
    <p>After looking at how the <a href="http://www.asp.net/MVC/gallery/View.aspx?itemid=77" rel="nofollow noreferrer">Orange Tabs</a> ASP.NET MVC demo handles tabs, they have something like:</p> <p>View:</p> <pre><code>&lt;ul id="menu"&gt; &lt;% if (Html.IsCurrentAction("Index", "Home")) { %&gt; &lt;li class="active"&gt;&lt;%= Html.ActionLink("Home", "Index", "Home")%&gt;&lt;/li&gt; &lt;% } else { %&gt; &lt;li&gt;&lt;%= Html.ActionLink("Home", "Index", "Home") %&gt;&lt;/li&gt; &lt;% }%&gt; &lt;% if (Html.IsCurrentAction("About", "Home")) { %&gt; &lt;li class="active"&gt;&lt;%= Html.ActionLink("About", "About", "Home")%&gt;&lt;/li&gt; &lt;% } else { %&gt; &lt;li&gt;&lt;%= Html.ActionLink("About", "About", "Home")%&gt;&lt;/li&gt; &lt;% }%&gt; &lt;% if (Html.IsCurrentAction("SampleTags", "Home")) { %&gt; &lt;li class="active"&gt;&lt;%= Html.ActionLink("Sample Tags", "SampleTags", "Home")%&gt;&lt;/li&gt; &lt;% } else { %&gt; &lt;li&gt;&lt;%= Html.ActionLink("Sample Tags", "SampleTags", "Home")%&gt;&lt;/li&gt; &lt;% }%&gt; &lt;/ul&gt; </code></pre> <p>and a corresponding helper class:</p> <pre><code>namespace Helpers { public static class IsCurrentActionHelper { public static bool IsCurrentAction(this HtmlHelper helper, string actionName, string controllerName) { string currentControllerName = (string)helper.ViewContext.RouteData.Values["controller"]; string currentActionName = (string)helper.ViewContext.RouteData.Values["action"]; if (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase) &amp;&amp; currentActionName.Equals(actionName, StringComparison.CurrentCultureIgnoreCase)) return true; return false; } } } </code></pre> <p>Does this seem like an elegant way to approach this problem? I've seen dozens of different ways from javascript to query strings, etc.</p> <p>I don't like javascript because I want the website to be fine for non-js enabled browsers and the query string approach seems cludgey.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload