Emre Utku Solak
Emre Utku Solak

Reputation: 316

Doesn't razor accept space as the first character when concat strings?

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?

Upvotes: 2

Views: 61

Answers (1)

Victor
Victor

Reputation: 8950

Add additional quotes:

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

Upvotes: 3

Related Questions