1

What I mean is, e.g.

[DataType(DataType.Text)]
[Display(Name = "Corporation / Entreprise")]
public string Corporation { get; set; }

Would it be possible to apply a line break after the '/' in the Name of the Display attribute? So when the View page displaying the label value which set in the Model:

<td class="col-md-6" style="font-weight:bold">
    @Html.DisplayNameFor(model => model.Corporation)
</td>

It would show something like:

Corporation / 
Entreprise

Instead of

Corporation / Entreprise

Thanks in advance.

Xiao Han
  • 1,004
  • 7
  • 16
  • 33
  • What happens if you put a `\n` in the attribute property value? If it doesn't render a newline, I'd consider rolling my own with some reflection. – Mathieu Guindon Jul 27 '22 at 22:08

1 Answers1

2

Add the <br/> attribute in displayattribute and display it as Html.Raw in the view. like this:

Model:

[DataType(DataType.Text)]
[Display(Name = "Corporation / <br/> Entreprise")]
public string Corporation { get; set; }

View:

<td class="col-md-6" style="font-weight:bold">
      @Html.Raw(@Html.DisplayNameFor(model => model.Corporation))
</td>

Test Result:

enter image description here

Chen
  • 4,499
  • 1
  • 2
  • 9
  • Just a quick question, would I be able to use @Html.Raw to the label tag which uses the model value set for Corporation like – Xiao Han Sep 23 '22 at 14:50