mz1378
mz1378

Reputation: 2602

how to prevent MarkupString from automatically closing Tags in Blazor

I have this code that I expect to work but MarkupString closes the tag that is not supposed to close:

@((MarkupString)startMarkup)    
int count = 0;
foreach (int metaID in MetaIDs)
{
    if (count % 3 == 0 && count != 0)
    {
        @((MarkupString)endMarkup)
    }
    <div class="col-md-4">
       @: A component here
    </div>
    count++;
}

There are two variables that blazor automatically close them:

string startMarkup = "<div class=\"row\">";
string endMarkup = "</div><div class=\"row\">";

How to make this page that is a grid of 3 item rows to work?

Upvotes: 6

Views: 734

Answers (1)

enet
enet

Reputation: 45704

I don't think this is possible, as Blazor manipulates the DOM Elements, and they must be valid as soon as they are created. Thus,your markup string must be complete and valid; that is, it should have the closing tag right after the opening tag, like this:

string myMarkup = "<div class=\"row\"></div>";

Devise a way to build your grid without using MarkupString

Hope this helps...

Upvotes: 2

Related Questions