如何在asp.net MVC 3 中获取当前视图名称? [英] How to get the current view name in asp.net MVC 3?

查看:15
本文介绍了如何在asp.net MVC 3 中获取当前视图名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Razor 引擎在 asp.net MVC 3 中获取关于当前 URL 的当前视图名称?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆