You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sonarr/NzbDrone.Web/Helpers/IsCurrentActionHelper.cs

64 lines
2.1 KiB

using System.Linq;
using System;
14 years ago
using System.Web.Mvc;
using System.Web.Mvc.Html;
namespace NzbDrone.Web.Helpers
14 years ago
{
public static class IsCurrentActionHelper
{
private static bool IsCurrentController(HtmlHelper helper, string controllerName)
14 years ago
{
var currentControllerName = (string) helper.ViewContext.RouteData.Values["controller"];
14 years ago
if (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase))
return true;
return false;
}
private static bool IsCurrentAction(HtmlHelper helper, string actionName, string controllerName)
{
var currentControllerName = (string)helper.ViewContext.RouteData.Values["controller"];
var currentActionName = (string)helper.ViewContext.RouteData.Values["action"];
if (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase) &&
currentActionName.Equals(actionName, StringComparison.CurrentCultureIgnoreCase))
return true;
return false;
}
public static string CurrentControllerLink(this HtmlHelper helper, string text, string actionName, string controllerName)
14 years ago
{
string result;
if (IsCurrentController(helper, controllerName))
14 years ago
{
result = "<li class='current_page_item'>";
}
else
{
result = "<li>";
}
return result + helper.ActionLink(text, actionName, controllerName).ToHtmlString() + @"</li>";
}
public static string CurrentActionLink(this HtmlHelper helper, string text, string actionName, string controllerName)
{
string result;
if (IsCurrentAction(helper, actionName, controllerName))
{
result = "<li class='current_action'>";
}
else
{
result = "<li>";
}
return result + helper.ActionLink(text, actionName, controllerName).ToHtmlString() + @"</li>";
}
14 years ago
}
}