简体   繁体   English

Asp.net 内核如何在视图中获取当前页面?

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

How can i check out the active sections except for ViewBag.Title我如何查看除 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 :您可以检查ViewContext.RouteData

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 ASP.NET Core 获取当前路由名称? - How can I get the current route name with ASP.NET Core? 如何通过 asp.net 核心获取当前计算机的域? - How can I get the current computer´s domain via asp.net core? 如何在ASP.NET Core MVC中获取当前日期? - How can I get the current date in ASP.NET Core MVC? 如何在ASP.Net core 2.1 Web API中查看“默认控制器”页面? - How can I make a view of a Controller as Default page in ASP.Net core 2.1 Web API? ASP.NET 核心 MVC 身份 - 如何查看当前登录的用户? - ASP.NET Core MVC Identity - how to get current logged in user in view? 如何在ViewComponent Asp.Net Core中获取当前登录用户 - How get current login user in ViewComponent Asp.Net Core 如何在 asp.net 内核中获取当前用户 ID - How to get current userId in asp.net core asp.net core中如何获取当前用户 - How to get current user in asp.net core 如何在 ASP.NET Core 3.1 中获取当前的 JsonSerializerOptions? - How to get current JsonSerializerOptions in ASP.NET Core 3.1? 如何让用 ASP.Net Core 2.0 编写的自定义异常处理程序在 ASP.Net Core 3.1 中工作? - How can I get a custom exception handler written in ASP.Net Core 2.0 to work in ASP.Net Core 3.1?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM