asp.netasp.net-mvcdisplayattribute

ASP MVC non-breaking-space in Display attribute with DisplayNameFor


I have a model with a Property "Price" which has the DisplayAttribute

[Display(Name = "Price (in €)")]

Now i want to display this in a table header using

@Html.DisplayNameFor(model => model.Price)

But when the column is very small, the Text might be broken into two Lines:

Price (in
€)

But i want it to break this way:

Price
(in €)

Is it possible to insert a non breaking space into the Display attribute? Using "Price (in €)" results in the " " printed as Text.


Solution

  • Andrei posted the correct Answer in the comments: Non breaking space is a unicode character, with code 00a0. So this should work:

    [Display(Name = "Price (in\u00a0€)")]