How to change the display name for LabelFor in razor in mvc3?

前端 未结 5 1908
日久生厌
日久生厌 2021-01-30 15:22

In razor engine I have used LabelFor helper method to display the name

But the display name is seems to be not good to display. so i need to change my displ

5条回答
  •  逝去的感伤
    2021-01-30 16:03

    You could decorate your view model property with the [DisplayName] attribute and specify the text to be used:

    [DisplayName("foo bar")]
    public string SomekingStatus { get; set; }
    

    Or use another overload of the LabelFor helper which allows you to specify the text:

    @Html.LabelFor(model => model.SomekingStatus, "foo bar")
    

    And, no, you cannot specify a class name in MVC3 as you tried to do, as the LabelFor helper doesn't support that. However, this would work in MVC4 or 5.

提交回复
热议问题