How can I get the current view name regarding to current URL, in asp.net MVC 3 using Razor engine?
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- Request.PathInfo issues and XSS attacks
- How to dynamically load partial view Via jquery aj
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- “Dynamic operations can only be performed in homog
- What is the best way to create a lock from a web a
- Add to htmlAttributes for custom ActionLink helper
You can get it from RequestContext.RouteData specifically, its Values collection contains "controller" and "action" keys i.e. RequestContext.RouteData.Values["controller"] RequestContext.RouteData.Values["action"]
No idea why you would need to get the current view name but you could use the
VirtualPath
property inside a view. Normally it's more useful to know the current action or controller. But anyway, here's how to get the current view name:and if you wanted to get only the filename:
and without the extension:
ASP.NET Core's equivalent:
Output is like this:
I've also tested this code, and I could do something with it. But, I'm not sure if is this a good solution or not.
For example, I need to detect the Contacts view located in Home directory. So I wrote: