I have a dropdownlistfor :
@Html.DropDownListFor(model => model.Item.Item.Status, new SelectList(@Model.AllStatus, "id", "Description"), new { id = "statusDropdown" }) @Html.ValidationMessageFor(model => model.Item.Item.Status)
HTML output:
<select id="statusDropdown" class="valid" name="Item.Item.Status" data-val-required="The Status field is required." data-val-number="The field Status must be a number." data-val="true"> <option value="2">Completed by Admin</option> <option value="3">General Error</option> <option value="4">New</option> </select>
How can I update this code to set the default option? For instance.
<option value="4" selected>New</option>
I tried:
@Html.DropDownListFor(model => model.Item.Item.Status, new SelectList(@Model.AllStatus, "id", "Description",@Model.SelectedStatusIndex), new { id = "statusDropdown" })
@Model.SelectedStatusIndex is 4, but does not change the default setting to New.
I also tried:
@Html.DropDownListFor(model => model.SelectedStatusIndex, new SelectList(@Model.AllStatus, "id", "Description"), new { id = "statusDropdown" }) @Html.ValidationMessageFor(model => model.Item.Item.Status)
This selects the default option "New", but model.Item.Item.Status not set by a drop-down list in the HTTP POST.
Other information:
model.Item.Item.Status is an int. @Model.AllStatus is an SQL table listing all available state parameters.