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 display name how to do it....
@Html.LabelFor(model => model.SomekingStatus, new { @class = "control-label"})
You can change the labels' text by adorning the property with the DisplayName attribute.
Html.Label gives you a label for an input whose name matches the specified input text (more specifically, for the model property matching the string expression): // Model public string Test { get; set; } // View @Html. Label("Test") // Output <label for="Test">Test</label>
The @ symbol is used in Razor initiate code, and tell the compiler where to start interpreting code, instead of just return the contents of the file as text. Using a single character for this separation, results in cleaner, compact code which is easier to read.
Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With