Reputation: 3437
I try to reuse HTML snippets in my razor page (view component) but somehow it never call or hit the break in the html section.
I'm using 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);
}
Upvotes: 4
Views: 2525
Reputation: 3437
somehow it only works with @ though the method call is inside the server side syntax
@if (root.Manufacturers.Count > 0)
{
@DisplayManufacturerPicture(root);
}
Upvotes: 2
Reputation: 387657
What you are trying to do is not (yet) possible. You should take a look at partial views instead:
@foreach (var root in Model.Categories)
{
<partial name="_DisplayManufacturerPicture" model="root" />
}
And then inside _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>
Upvotes: 1