gpt4 book ai didi

asp.net-mvc - ASP.NET MVC : How do I output the Controller and View that is currently being rendered?

转载 作者:行者123 更新时间:2023-12-02 18:12:59 26 4
gpt4 key购买 nike

我有一组复杂的路线,我需要编辑特定的网页。给定一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com