@IshanJain @RoryMcCrossan @ j08691 @EliantenHolder謝謝你的迴應。 Jquery沒有幫助解決這個問題,但這個幫手工作。
public static class HtmlHelperExtensions
{
public static string ActivePage(this HtmlHelper htmlHelper,string controller, string action)
{
string _classValue="";
string _currentController = htmlHelper.ViewContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString();
string _currentAction = htmlHelper.ViewContext.Controller.ValueProvider.GetValue("action").RawValue.ToString();
if (_currentController == controller && _currentAction == action)
{
_classValue = "active";
}
else if (_currentController == controller && action.Equals(""))
{
_classValue = "has-sub active";
}
else
{
if (action.Equals(""))
{
_classValue = "has-sub";
}
}
return _classValue;
}
}
,這是從我的佈局頁
<li class="@Html.ActivePage("Order","")">
<a href="javascript:;" class="">
<span class="icon-box"> <i class="icon-dashboard"></i></span> Sipariş Açma
<span class="arrow"></span>
</a>
<ul class="sub">
<li class="@Html.ActivePage("Order","Index")"><a class="" href="@Url.Action("Index","Order")">Sipariş</a></li>
<li class="@Html.ActivePage("Order","orderProduct")"><a class="" href="@Url.Action("orderProduct","Order")">Ürün Sipariş</a></li>
<li class="@Html.ActivePage("Order","orderCloth")"><a class="" href="@Url.Action("orderCloth","Order")">Kumaş Sipariş</a></li>
<li class="@Html.ActivePage("Order","orderAccessory")"><a class="" href="@Url.Action("orderAccessory","Order")">Aksesuar Sipariş</a></li>
</ul>
</li>
''#ids''是字面上的字符串'#ids'。它與你的變量沒有關係。你爲什麼試圖從元素的'id'屬性中構造一個選擇器?那個選擇器不會再次匹配'this'元素嗎?或者你是否存儲了你不應該在'id'屬性中的東西? – Blender