asp.net core 视图组件化
视图组件可以通过partial view或viewcomponent实现
partialview
https://docs.microsoft.com/zh-cn/aspnet/core/mvc/views/partial?view=aspnetcore-2.2
https://github.com/aspnet/AspNetCore.Docs/tree/master/aspnetcore/mvc/views/partial/sample/PartialViewsSample
https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/partial-tag-helper?view=aspnetcore-2.2
@foreach (var section in Model.Article.Sections)
{
@await Html.PartialAsync("_ArticleSectionRP", section,
new ViewDataDictionary(ViewData)
{
{ "index", index }
})
index++;
}
<partial name="_ProductViewDataPartial" for="Product" view-data="ViewData">
view component
https://docs.microsoft.com/zh-cn/aspnet/core/mvc/views/view-components?view=aspnetcore-2.2
https://github.com/aspnet/AspNetCore.Docs/tree/master/aspnetcore/mvc/views/view-components/sample
本文采用 知识共享署名 4.0 国际许可协议 进行许可