我想在MVC剃须刀的Html.LabelFor上强制大写?

时间:2014-01-09 07:02:46

标签: asp.net-mvc razorengine

我使用MVC Razor作为我的View引擎。我想在Html.LabelFor强制使用大写字母我尝试了以下技巧但不适合我!!

请帮我一个人!

@Html.LabelFor(model => model.YearID.ToString ().ToUpper())

以上代码给出以下错误: 模板只能用于字段访问,属性访问,单维数组索引或单参数自定义索引器表达式。

 @Html.LabelFor(model => model.YearID).ToString().ToUpper()

以上代码正常工作,但显示与html代码一样显示:

<LABEL FOR="STUDENTENROLLPLANS_SCHOOLYEARID">你的学年会是哪一年?</LABEL>

3 个答案:

答案 0 :(得分:4)

您可以在YearID属性中添加DisplayAttribute,并以大写字母为其命名

[Display(Name = "WHICH SCHOOL YEAR ARE YOUR ENROLLING FOR?")]
public int YearID { get; set; }

在这种情况下,YearID的每个标签都将为大写。如果只想要特定标签,请创建一个CSS类并将其应用于标签:

.uppercase {
    text-transform: uppercase;
}

@Html.LabelFor(model => model.YearID , new { @class = "uppercase"})

答案 1 :(得分:0)

@Html.Encode(item.Employee_Name).ToUpper() 这是我的计划中的工作。我可以通过此代码将所有字母显示为大写

答案 2 :(得分:0)

如果//Calculate the expected size based on the font and linebreak mode of your label // FLT_MAX here simply means no constraint in height CGSize maximumLabelSize = CGSizeMake(296, FLT_MAX); CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font constrainedToSize:maximumLabelSize lineBreakMode:yourLabel.lineBreakMode]; //adjust the label the the new height. CGRect newFrame = yourLabel.frame; newFrame.size.height = expectedLabelSize.height; yourLabel.frame = newFrame; 是您唯一要找的东西,那么这应该适合您!

  var DummyObject = Parse.Object.extend("dummyFlow2");
  var dummyObject = new DummyObject();
  var query = new Parse.Query(DummyObject);
  query.equalTo("oneT", 280);
  query.find({
    success: function(results) {
        alert("Successfully retrieved " + results.length + " scores.");
        // Do something with the returned Parse.Object values
        console.log(results);
        console.log(results[0]);
      },
      error: function(error) {
        alert("Error: " + error.code + " " + error.message);
      }
    });

显示文字有重载。您可以输入纯文本或使用帮助程序。
生成的HTML

@Html.LabelFor()