有没有办法改变我的占位符只是读取我的模型的显示名称属性?(Is there a way to change my placeholder to just read the display name a

编程入门 行业动态 更新时间:2024-10-27 01:35:48
没有办法改变我的占位符只是读取我的模型的显示名称属性?(Is there a way to change my placeholder to just read the display name attribute of my model?)

有没有办法改变我的占位符只是读取我的模型的显示名称属性?

目前我有这行代码。

@Html.TextBoxFor(x => x.Address1, new { @class = "form-control text-center", @placeholder = "Address Line 1" })

我希望占位符只使用我在模型中的displayname属性。

[Display(Name = "Address Line 1")] public string Address1 { get; set; }

修订:尝试但未获得占位符显示。

@Html.TextBoxFor(x => x.Address1, new { @class = "form-control text-center", @placeholder = ViewData.ModelMetadata.DisplayName })

Is there a way to change my placeholder to just read the display name attribute of my model?

Currently I have this line of code.

@Html.TextBoxFor(x => x.Address1, new { @class = "form-control text-center", @placeholder = "Address Line 1" })

I would prefer the placeholder to just use the displayname attribute that I have in my model.

[Display(Name = "Address Line 1")] public string Address1 { get; set; }

Revision: Tried but not getting placeholder to show.

@Html.TextBoxFor(x => x.Address1, new { @class = "form-control text-center", @placeholder = ViewData.ModelMetadata.DisplayName })

最满意答案

这似乎可以解决问题......

@Html.TextBoxFor(x => x.Address1, new { @class = "form-control text-center", @placeholder = @Html.DisplayNameFor(x => x.Address1) })

This appears to do the trick...

@Html.TextBoxFor(x => x.Address1, new { @class = "form-control text-center", @placeholder = @Html.DisplayNameFor(x => x.Address1) })

更多推荐

Address,placeholder,占位符,@Html,Line,电脑培训,计算机培训,IT培训"/> <meta name=

本文发布于:2023-08-04 12:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415910.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有办法   属性   模型   名称   change

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!