如何在asp.net MVC 3获取当前视图的名字吗? [英] How to get the current view name in asp.net MVC 3?
本文介绍了如何在asp.net MVC 3获取当前视图的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何才能让当前视图名称就目前的URL,在asp.net MVC 3使用剃刀引擎?
How can I get the current view name regarding to current URL, in asp.net MVC 3 using Razor engine?
推荐答案
不知道你为什么会需要获得当前视图名称,但你可以使用里面的 VirtualPath
属性一个看法。通常它更为有用知道当前的操作或者控制器。但无论如何,这里是如何获取当前视图名称:
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:
@VirtualPath
如果你想获得唯一的文件名:
and if you wanted to get only the filename:
@Path.GetFileName(Server.MapPath(VirtualPath))
和不带扩展名:
@Path.GetFileNameWithoutExtension(Server.MapPath(VirtualPath))
这篇关于如何在asp.net MVC 3获取当前视图的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文