gpt4 book ai didi

asp.net - MVC 6 View 组件与部分 View : What is the difference? 何时应分别使用?

转载 作者:行者123 更新时间:2023-12-03 05:52:27 25 4
gpt4 key购买 nike

MVC 6 引入了 View 组件,并表示它比部分 View 更强大、更灵活。 View 组件是否要取代部分 View ?每种实现有什么区别以及需要什么类型的情况?

最佳答案

根据此链接-https://docs.asp.net/en/latest/mvc/views/view-components

New to ASP.NET MVC 6, view components (VCs) are similar to partial views, but they are much more powerful. VCs include the same separation-of-concerns and testability benefits found between a controller and view. You can think of a VC as a mini-controller—it’s responsible for rendering a chunk rather than a whole response.

所以它只是部分 View 的增强,另一个区别是当您使用部分 View 时您仍然依赖于 Controller ,而在 View 组件中您不需要 Controller 。因此存在关注点分离。

有一篇关于 ASP.NET View 组件的详细文章。 http://www.tugberkugurlu.com/archive/exciting-things-about-asp-net-vnext-series-mvc-view-components

关于asp.net - MVC 6 View 组件与部分 View : What is the difference? 何时应分别使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29823507/

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