何时适合使用Html.RenderAction()?(When Is It Appropriate to Use Html.RenderAction()?)

编程入门 行业动态 更新时间:2024-10-24 20:21:39
何时适合使用Html.RenderAction()?(When Is It Appropriate to Use Html.RenderAction()?)

我有点不确定什么时候适合使用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.

更多推荐

本文发布于:2023-08-07 13:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464269.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适合   Html   RenderAction

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!