我尝试在我的剃须刀页面(查看组件)中重用HTML代码段,但是以某种方式它从未调用或击中html部分的中断。
我正在使用Asp.net core 2.2
@{
Func<CategorySimpleModel, Microsoft.AspNetCore.Html.IHtmlContent> DisplayManufacturerPicture=
@<div class="col-sm-4">
<div class="row">
@foreach (var m in item.Manufacturers)
{
<div class="col-md-6 col-sm-12">
blah blah
</div>
}
</div>
</div>;
}
@foreach (var root in Model.Categories)
{
DisplayManufacturerPicture (root);
}
答案 0 :(得分:0)
您尚未尝试做的事情。您应该改为查看partial views:
@foreach (var root in Model.Categories)
{
<partial name="_DisplayManufacturerPicture" model="root" />
}
然后在_DisplayManufacturerPicture.cshtml
内:
@model CategorySimpleModel
<div class="col-sm-4">
<div class="row">
@foreach (var m in item.Manufacturers)
{
<div class="col-md-6 col-sm-12">
blah blah
</div>
}
</div>
</div>
答案 1 :(得分:0)
尽管方法调用在服务器端语法内部,但它只能以@方式工作
@if (root.Manufacturers.Count > 0)
{
@DisplayManufacturerPicture(root);
}