Reputation: 2248
I am using MVC Razor as my View engine. I want to force uppercase on Html.LabelFor
I tried the following techniques but not working for me!!
Please help me some one!
@Html.LabelFor(model => model.YearID.ToString ().ToUpper())
Above code giving below error: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
@Html.LabelFor(model => model.YearID).ToString().ToUpper()
Above code working but out put showing along with html code like this:
<LABEL FOR="STUDENTENROLLPLANS_SCHOOLYEARID">
WHICH SCHOOL YEAR ARE YOUR ENROLLING FOR?</LABEL>
Upvotes: 1
Views: 11531
Reputation: 87
@Html.Encode(item.Employee_Name).ToUpper()
this is work in my program. I can display all the letters as capital by this code
Upvotes: 3
Reputation: 7752
If @Html.LabelFor()
is the only thing you are looking for then this should work for you!
@Html.LabelFor(model => model.YearID, Html.DisplayNameFor(model => model.YearID).ToString().ToUpper())
there is an overload for a display text. You can enter a plain text or use a helper.
Generated HTML
<label for="YearID">WHICH SCHOOL YEAR ARE YOUR ENROLLING FOR?</label>
Upvotes: 1
Reputation: 13640
You can add a DisplayAttribute to the YearID
property and give it a name already in uppercase
[Display(Name = "WHICH SCHOOL YEAR ARE YOUR ENROLLING FOR?")]
public int YearID { get; set; }
In this case every label for YearID
will be in uppercase. If you want only for specific labels, create a CSS class and aplly it to the label:
.uppercase {
text-transform: uppercase;
}
@Html.LabelFor(model => model.YearID , new { @class = "uppercase"})
Upvotes: 6