【问题标题】:Create a Line break in the Identity Status Message在身份状态消息中创建换行符
【发布时间】:2021-12-02 10:34:12
【问题描述】:

我想在状态消息中创建一个换行符。这是我尝试过的代码,但它不会创建新行。我正在使用 Asp.net Razor 中 Identity 中使用的状态消息。

在cshtml页面上

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

在同一页面上,我将以下内容添加到脚本中

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

在 .cs 页面上

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

结果是:每周提醒电子邮件通知已更改。已发送

我也试过 +Enviroment.NewLine();结果相同。

我希望它成为 每周提醒电子邮件通知已更改。
已发送。

谢谢

【问题讨论】:

标签: c# asp.net razor


【解决方案1】:

我知道两种方法,你可以同时尝试,看看你能理解哪种方法

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

或者干脆试试这个

StatusMessage = "Weekly Reminders email Notifications have been changed.";
StatusMessage = "\r\n";
StatusMessage = "Sent";

【讨论】:

  • 这使它在生成的 HTML 中为您正确呈现?
  • 我不知道你的情况是我无法测试它你必须自己测试它
  • 另外\x0A\n 有何不同? Aren't they the same thing?.
  • 我的情况与 OP 的问题有什么关系?您要回答的是 OP 的问题,并且 OP 正在使用 Razor(因此该消息以 HTML 格式呈现)。
  • 我试过了,但没有用。唯一显示的东西是发送的。 StatusMessage = "每周提醒电子邮件通知已更改。\x0A";显示发送后的消息。
猜你喜欢
  • 2023-04-07
  • 1970-01-01
  • 2022-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-09
  • 2016-07-31
  • 1970-01-01
相关资源
最近更新 更多