简体   繁体   中英

Asp.net core how can i get current page in View?

How can i check out the active sections except for ViewBag.Title

<li id="home"><a class="@(ViewBag.Title == "Anasayfa" ? "active" : "")" asp-action="Index" asp-controller="Home">Anasayfa</a></li>
<li id="download"><a class="@(ViewBag.Title == "Oyunu İndir" ? "active" : "")" asp-controller="Download" asp-action="Index">Oyunu İndir</a></li>
<li id="mall"><a class="@(ViewBag.Title == "Market" ? "active" : "")" asp-action="Index" asp-controller="Store">Market</a></li>
<li id="faq"><a class="@(ViewBag.Title == "Kullanıcı İstatistikleri" ? "active" : "")" asp-action="Index" asp-controller="UserStats">İstatistikler</a></li>
<li id="ranking"><a class="@(ViewBag.Title == "Sıralama" ? "active" : "")" asp-action="Index" asp-controller="Ranking">Sıralama</a></li>
<li id="contact"><a class="@(ViewBag.Title == "İletişim" ? "active" : "")" asp-action="Index" asp-controller="Contact">İletişim</a></li>

You can check ViewContext.RouteData :

 var controllerName = ViewContext.RouteData.Values["controller"]?.ToString();
 var razorPageName = ViewContext.RouteData.Values["page"]?.ToString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM