I want to place the value of a field (property) from model into Html.Label. Something like this:
@Html.Label(item => item.Title)
I don't want a label for item.Title (like Html.LabelFor( model => model.Title)
). But I want to put the value of item.Title
in the label as text (string). So the result in run-time should be like this:
<label>Some Title</label>
How can I do this?
Use the textContent property to get the text of a label element, e.g. const text = label. textContent . The textContent property will return the text content of the label and its descendants.
A data-* attribute on a <label> tag attaches additional data to the label. To create a custom attribute, replace * with a lowercase string, such as data-id , data-status , or data-location .
LabelFor() The Html. LabelFor<TModel,TProperty>() helper method is a strongly typed extension method. It generates a html label element for the model object property specified using a lambda expression.
The label is specified by using the Label Attribute applied to the property.
Try this:
@Html.Label(Model.Title)
It should work
EDITED
or this:
<label>@Html.DisplayFor(item => item.Title)</label>
<label>@Model.Title</label>
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