skip to Main Content

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

2

Answers


  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 = "rn";
    StatusMessage = "Sent";
    
    Login or Signup to reply.
  2. 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 AreasIdentityPagesAccount_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>
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search