Issue
I'm trying to add comma(,) after "a" tag in foreach like this:
@foreach (var item in Model.Product.Categories)
{
<a href="#" class="product-link product-cat-title">@item.Name</a>
,
}
but I'm getting error that says "} Expected". What should I do?
I've tested @string.join(", ", Model.Categories.Select(p => p.Name).ToArray())
but that will return string or text. I want Link!
It's worth mentioning that I don't want to add another tag Like <span>
or <a>
. I know they Work. And I'll appreciate if someone could explain why it doesn't work?
Thanks
Solution
Use this approach to render HTML that isn't surrounded by an HTML tag. Without an HTML or Razor tag, a Razor runtime error occurs
@foreach (var item in Model.Product.Categories)
{
<a href="#" class="product-link product-cat-title">@item.Name</a>
<text >,</text>
}
Answered By - Qiang Fu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.