我有点不确定什么时候适合使用Html.RenderAction()来渲染我的Views,什么时候不用。 我的理解是,因为它不是ASP.NET MVC的“官方”组件,所以使用它是不好的做法,它的初衷是针对任何特定Controller上下文中不存在的可重用小部件。
事情是,当我需要一个不同于我目前正在渲染View的Controller的组件时,RenderAction非常有用。 我认为这是一种非常整洁和独立的方式来呈现依赖于当前视图中不可用数据的组件。 我的视图不需要提供模型,因为如果我使用RenderPartial()
这是不好的做法吗? 有没有更好的办法?
I'm a little bit unsure about when it's appropriate to use Html.RenderAction() to render my Views and when not to. My understanding is that because it's not an 'official' component of ASP.NET MVC it's bad practice to use it, and its original intention was for reusable widgets that don't exist in any specific Controller context.
The thing is, RenderAction is very useful when I need a component that exists under a different Controller than the one that I'm currently rendering the View for. I think it's a very tidy & self contained way to render components that rely on data unavailable in the current View. My View doesn't need to supply the Model, as it would if I was using RenderPartial()
Is this bad practice? Is there a better way?
最满意答案
它可以解决您的问题。
It's OK in case it solves your problem.
更多推荐
发布评论