19

So using annotations my default label for a field is [Display(Name = "Spent")]

But of course depending on the context the field is displayed in I would like to change it in the View to say "Spent $".

For the label, MVC5 scaffolding generates... @Html.LabelFor(model => model.Spend Amount, htmlAttributes: new { @class = "control-label col-md-2" })

and so the label is "Spent".

How can I make it "Spent $" in the view..??

1
  • why don't ypu change DisplayName attribute Commented Jul 7, 2014 at 7:48

1 Answer 1

67

Use this overloaded LabelFor method

@Html.LabelFor(model => model.SpendAmount, "Spent $", htmlAttributes: new { @class = "control-label col-md-2" })
Sign up to request clarification or add additional context in comments.

2 Comments

I tried to vote up but I needed 15 reputations. Can anyone give me a reputation please. I am a very experienced programmer in many areas but not ASP.NET in general.
It is enough to me to accept my answer as solution :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.