Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法动态执行 ASP.NET MVC 全局帮助函数(不是 HtmlHelper 扩展方法),类似于使用反射方法调用类上的方法?我需要能够动态调用方法,并将响应注入到视图中。
谢谢。
假设您根据视图可以访问的值来决定执行哪个帮助器,您可以将每个帮助器函数封装在部分视图中(或者只是将帮助器重构为部分)并直接使用@Html.RenderPartial. 如果您想要两个视图之间的更多隔离和更大的灵活性,请@Html.RenderAction改为使用(但请注意,当您从视图调用子操作时,您正在重新调用 MVC 管道的中大型部分)。
@Html.RenderPartial
@Html.RenderAction