How to add a new line into Display Attribute, Name field

被刻印的时光 ゝ 提交于 2019-12-02 14:38:33

问题


I'm working on an MVC3 application and am using data attributes for the display name fields on the screen. Below is a representative sample -

    [Required]
    [Display(Name = "Staff Id (format \"9999\")")]
    [StringLength(10)]
    [UIHint("StaffId")]
    public string StaffId { get; set; }

What I would like to do is to have the name display on two lines with line break right after "Id" text. So it would display as

   Staff Id
   (format "9999")

Is there a way to do this?


回答1:


[Required]
[Display(Name = "Staff Id<br/>(format \"9999\")")]
[StringLength(10)]
[UIHint("StaffId")]
public string StaffId { get; set; }

and inside your StaffId.cshtml custom editor template:

@model string
@Html.Raw(ViewData.ModelMetadata.DisplayName)
@Html.TextBox("")



回答2:


Just adding to @Darin-Dimitrov answer, it is important to use

@Html.Raw(your.property)

Instead of typical HTML helpers like

@Html.DisplayFor(modelItem=>item.property) -- will not work


来源:https://stackoverflow.com/questions/6879081/how-to-add-a-new-line-into-display-attribute-name-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!