Selamlar,
Solutionunuzda “Helpers” adında bir folder oluşturduktan sonra HtmlHepers.cs adında bir class oluşturuyorsunuz ve bu class aşağıdaki kodlardan oluşuyor.
public static class HtmlHelpers
{
public static string ActivePage(this HtmlHelper helper, string controller, string action)
{
string classValue = "";
string currentController = helper.ViewContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString();
string currentAction = helper.ViewContext.Controller.ValueProvider.GetValue("action").RawValue.ToString();
if (currentController == controller && currentAction == action)
{
classValue = "active";
}
return classValue;
}
}
Sonrasında _layout türevi menüyü yazdığınız yerde class=”@Html.ActivePage(“Home”,”Index”)” ekliyorsunuz. Bu size active stringini döndürecek. classValue=”active” bunu eğer active classınız farklıysa değiştirebilirsiniz.
İyi çalışmalar herkese..