如何在 [DisplayName] 注释中插入新行
无论如何,是否可以在 mvc 视图模型的 [DisplayName()] 注释中添加新行?我目前有一个属性:
[DisplayName("Delivery Time (if different from our normal delivery of 10-30am – 12.30pm):")]
public string DeliveryTime { get; set; }
并且我想在“交货时间”部分之后添加一个新行,以便括号中的位位于下面,这可能吗?我尝试过 \r\n
但没有成功。
Is there anyway of putting a new line in a [DisplayName()]
annotation of an mvc viewmodel? I currently have a property that is:
[DisplayName("Delivery Time (if different from our normal delivery of 10-30am – 12.30pm):")]
public string DeliveryTime { get; set; }
and I want to have a new line after the Delivery Time part so that the bit in brackets is below, is that possible? I've tried \r\n
but that didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,你遇到的问题是
\n
在 html 中被忽略。您需要使用
但这确实将您的属性元数据与使用 html 格式联系起来。Well, the problem you have is that
\n
is ignored in html. You'd need to use<br />
BUT that does tie your attribute metadata to using html formatting.我正在寻找更漂亮的解决方案,但解决方法在 如何在显示属性、名称字段中添加新行
总结一下,您将
(或
) 在您的 DisplayName 字符串中并用于
显示它。
I'm looking for a prettier solutions, but a work around is presented in How to add a new line into Display Attribute, Name field
To summarize you put a <br> (or <br/>) in your DisplayName string and use
to display it.
您可以在元素中使用
style="white-space: pre-line"
并在DisplayName
属性中使用\n
。至少,它对我有用。You can just use
style="white-space: pre-line"
in your element and\n
inDisplayName
attribute. At least, it worked for me.