문제

in my following View why do i get text"name" in label and value of name in textbox?

    @model IEnumerable<string>

    @foreach(var names in Model)
    {
        <div class="label">@Html.LabelFor(m=>names)</div>
        <div class="input-block-level">@Html.TextBoxFor(m=>names)</div>
        <br/>
    }

If i run this I get following view in browser

enter image description here

도움이 되었습니까?

해결책

Html.LabelFor reads the metadata from a model property and displays the name of the property. You can configure the displayed name with the Display or DisplayName attributes. Your model has no properties, so LabelFor is completely useless in your example.

What do you want to achieve? When you want to render a label with the value of the string just create a label:

<label>@names</label>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top