有没有办法改变我的占位符只是读取我的模型的显示名称属性?(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=
发布评论