Home > Back-end >  Doesn't razor accept space as the first character when concat strings?
Doesn't razor accept space as the first character when concat strings?

Time:12-10

I have the following element in .NET6 Application's razor view:

<input type="number" placeholder=@((Model.Child?.Name ?? "DefaultName")   " SomeExtraText")>

Expected output when the Name attribute is not null is: "Name SomeExtraText". However I only get "Name" as the output.

When I change " SomeExtraText" to "-SomeExtraText" I get the output as "Name-SomeExtraText".

I also tried using String.Format as follows:

<input type="number" placeholder=@(String.Format("{0}{1}",(Model.Child?.Name ?? "DefaultName"), " SomeExtraText"))>

but the result is same.

What is the reason for that?

CodePudding user response:

Add additional quotes:

<input type="number" placeholder="@((Model.Child?.Name ?? "DefaultName")   " SomeExtraText")">
  • Related