Adding line break to message for asp-alert-message modal

Viewed 186

So I'd like to show a modal with 2 lines with a line break between them, here is the tag:

<nop-alert asp-alert-id="updateAddressAlert" asp-alert-message="@string.Concat("message1", "<br/>", "message2")" />

But I can't seem to be able to use make a line break, I tried the above, I also tried string.Format and:

var str = $"{msg} <br/> {msg}";

var str1 = msg + " <br/> " + msg;

Of course \n will also not work, it seems I'm missing something but I can't figure it out, and I've lost too much time with this, any help would be appreciated.

1 Answers

First add style in your view

<style> 
[asp-alert-id="updateAddressAlert"]{ 
      white-space: pre; width: 60px; word-wrap: break-word;
} 
</style>

Then in the controller

var str = $"{msg1} {Environment.NewLine}{msg2}";

Based on this post multiple lines in C#.

Related