質問

I am doing the textbox code below but for some reason I am not getting the appropriate textbox being formulated.

Here is what I have:

@for (int i = 0; i < @Model.Options.Count; i++)
{
    <div class="col-lg-4">
        <label for="@Model.Options[i].Text">@Model.Options[i].Text</label>
        @Html.TextBoxFor(o => Model.Options[i].StringValue, new { name = Model.Options[i].Id, @class = "form-control", placeholder = "" })
    </div>
}

Here is what my HTML output looks like

<div class="col-lg-4">
        <label for="First Name">First Name</label>
        <input class="form-control"  name="Options[0].StringValue" placeholder="" type="text" value="">
    </div>

I was under the presumption that the code I have in my razor HTML helper would create a html textbox with the name equal to my model option id. Why am I getting Options_0 as the name?

役に立ちましたか?

解決

You can to use for this @Html.TextBox(), not @Html.TextBoxFor()

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top