0

I would like to create a line break in the status message. This is the code I have tried but it wont create a new Line. I am using the Status Message that is used in Identity in Asp.net Razor.

On the cshtml page

<partial name="Status Message" model="Model.Status Message" /> 

on the same page I added the following to the scripts

 <p style="white-space: pre-line">@Model.StatusMessage</p>

on the .cs page

if(user.WeeklyReminders  != Input.WeeklyReminders)
{
StatusMessage = "Weekly Reminders email Notifications have been changed. \n";
}
StatusMessage += "Sent";

Results is: Weekly Reminders email Notifications have been changed. Sent

I also tried +Enviroment.NewLine(); With the same result.

I want it to be Weekly Reminders email Notifications have been changed.
Sent.

Thanks

cbas007
  • 11
  • 3

2 Answers2

0

It took me a while to realise what was happening and it really bothered me I could not break and debug what was going on.

You are talking about the Identity Status Message and it does not use the shared _StatusMessage.html, but it has its own version. You first have to scaffold it (or copy the shared version to Areas\Identity\Pages\Account\_StatusMessage.cshtml) before you can edit it.

If you wrap the status message in a <div> with the correct white-space, it works as expected and the newlines in your string are honoured:

@model string

@if (!String.IsNullOrEmpty(Model))
{
    var statusMessageClass = Model.StartsWith("Error") ? "danger" : "success";
    <div class="alert alert-@statusMessageClass alert-dismissible" role="alert">
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        <div style="white-space: pre-line">@Model</div>
    </div>
}
H. de Jonge
  • 878
  • 7
  • 25
-1

I know of two methods you can try both and see which you understand

StatusMessage = "Weekly Reminders email Notifications have been changed. \x0A";

or just simply try this

StatusMessage = "Weekly Reminders email Notifications have been changed.";
StatusMessage = "\r\n";
StatusMessage = "Sent";
goor.auss
  • 29
  • 5
  • And this makes it render correctly in the resulting HTML for you? – ProgrammingLlama Oct 14 '21 at 01:51
  • I dont know what you situation is I cannot test it you have to test it for you self – goor.auss Oct 14 '21 at 01:53
  • Also how is `\x0A` different to `\n`? [Aren't they the same thing?](https://rextester.com/QKTB4557). – ProgrammingLlama Oct 14 '21 at 01:53
  • What does my situation have to do with OP's question? It's OP's question that you're answer is posted on, and OP is using Razor (and the message is therefore being rendered in HTML). – ProgrammingLlama Oct 14 '21 at 01:53
  • 1
    I tried this and it did not work. The only thing that showed was sent. the StatusMessage = "Weekly Reminders email Notifications have been changed. \x0A"; Showed the message with sent after. – cbas007 Oct 14 '21 at 02:06