Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reuse HTML snippets in asp.net core razor page?

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);
            }
like image 262
nam vo Avatar asked Oct 15 '25 03:10

nam vo


1 Answers

somehow it only works with @ though the method call is inside the server side syntax

 @if (root.Manufacturers.Count > 0)
{
   @DisplayManufacturerPicture(root);
}
like image 189
nam vo Avatar answered Oct 16 '25 23:10

nam vo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!