作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一组复杂的路线,我需要编辑特定的网页。给定一个 URL,我如何确定哪个 Controller 和 View 创建了该页面?
我愿意使用 ASP.NET MVC 将信息直接写入文本颜色==背景颜色的页面,或您可能推荐的任何其他颜色。
我想要一个可以在生产中使用的解决方案(其中 MVC 路由调试器被禁用)
最佳答案
您可以直接通过ViewContext
访问 Controller 和操作。
// ASP.Net MVC 3
ViewContext.Controller.ValueProvider.GetValue("controller").RawValue
ViewContext.Controller.ValueProvider.GetValue("action").RawValue
// ASP.Net MVC 2 and below:
ViewContext.Controller.ValueProvider["controller"].RawValue
ViewContext.Controller.ValueProvider["action"].RawValue
要获取 View ,请查看此 answer to a similar question by Phil Haack .
关于asp.net-mvc - ASP.NET MVC : How do I output the Controller and View that is currently being rendered?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9066047/
我是一名优秀的程序员,十分优秀!