Asp.net mvc如何更改@ html.labelfor中的默认标签文本

Tho*_*sAJ 16 asp.net asp.net-mvc razor

因此,使用注释我的字段的默认标签是 [Display(Name = "Spent")]

但当然,根据上下文显示字段,我想在视图中将其更改为"花费$".

对于标签,MVC5脚手架产生...... @Html.LabelFor(model => model.Spend Amount, htmlAttributes: new { @class = "control-label col-md-2" })

所以标签是"花了".

如何让它在视图中"花费$"???

Ali*_*hşi 49

使用此重载LabelFor方法

@Html.LabelFor(model => model.SpendAmount, "Spent $", htmlAttributes: new { @class = "control-label col-md-2" })
Run Code Online (Sandbox Code Playgroud)

  • 我试图投票,但我需要15个声誉。谁能给我一个名声。我在许多领域都是经验丰富的程序员,但总体而言不是ASP.NET。 (2认同)