Nach einem Blick auf, wie die Orange Tabs ASP.NET MVC-Demo Tabs behandelt, haben sie so etwas wie:Scheint dies ein guter Ansatz zum Implementieren von Registerkarten in ASP.NET MVC zu sein?
Ausblick:
<ul id="menu">
<% if (Html.IsCurrentAction("Index", "Home")) { %>
<li class="active"><%= Html.ActionLink("Home", "Index", "Home")%></li>
<% } else { %>
<li><%= Html.ActionLink("Home", "Index", "Home") %></li>
<% }%>
<% if (Html.IsCurrentAction("About", "Home"))
{ %>
<li class="active"><%= Html.ActionLink("About", "About", "Home")%></li>
<% } else { %>
<li><%= Html.ActionLink("About", "About", "Home")%></li>
<% }%>
<% if (Html.IsCurrentAction("SampleTags", "Home"))
{ %>
<li class="active"><%= Html.ActionLink("Sample Tags", "SampleTags", "Home")%></li>
<% } else { %>
<li><%= Html.ActionLink("Sample Tags", "SampleTags", "Home")%></li>
<% }%>
</ul>
und eine entsprechende Hilfsklasse:
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) && currentActionName.Equals(actionName, StringComparison.CurrentCultureIgnoreCase))
return true;
return false;
}
}
}
scheint dies Wie eine elegante Art, dieses Problem anzugehen? Ich habe Dutzende von verschiedenen Möglichkeiten gesehen, von Javascript zu Abfragezeichenfolgen, etc.
Ich mag Javascript nicht, weil ich will, dass die Website in Ordnung für nicht-js-fähigen Browsern und der Abfrage-String-Ansatz scheint Clundedy.