0

I'm trying to add space between two strings in razor file in Blazor project.

What I'm trying to achieve is to get string like $"{name}, {date}".

Its complicated because I want to set different style for {name} and {date}. So in razor file, I have something like

<span class="c1">@(name)</span>, <span class="c2">@(date)</span>

Unfortunately space between </span>, and <span> is ignored. I also tried the following:

<span class="c1">@(name), </span><span class="c2">@(date)</span>
<span class="c1">@(name)</span><text>, </text><span class="c2">@(date)</span>

Every time I get "name,date" instead of "name, date"

I know I can achieve it by

@($"<span class=\"c1\">{name}</span>, <span class=\"c2\">{date}</span>")
//or
<span class="c1">@(name)@(", ")</span><span class="c2">@(date)</span>
//or
<span class="c1">@($"{name}, ")</span><span class="c2">@(date)</span>
//or maybe
<span class="c1">@name</span><span class="c2 ps-1">@(date)</span>

But is there any "clean" or preferred way just to not ignore the space key in such situations?

Endi
  • 17
  • 4
  • If you mean this one [@(name), @(date)] I was expecting it will work fine. Unfortunately in Blazor razor file it is not in my case. – Endi Oct 22 '22 at 18:29

1 Answers1

2

You can try adding &nbsp; But generally speaking what you displayed should work. Maybe your CSS Stylesheet is messing with the spacing.

You can see your code example here, without using any stylesheet. https://blazorfiddle.com/s/wocsxsy3

Devian
  • 817
  • 1
  • 12
  • 22