This is my View Code:
@using(Html.BeginForm(new { SelectedId = /*SelectedValue of DropDown*/ })) {
<fieldset>
<dl>
<dt>
@Html.Label(Model.Category)
</dt>
<dd>
@Html.DropDownListFor(model => Model.Category, CategoryList)
</dd>
</dl>
</fieldset>
<input type="submit" value="Search" />
}
As code shown I need to pass the dropdown
selected value to the action in BeginForm()
Html helper. What is your suggestion?
The selected value will be passed when the form is submitted because the dropdown list is represented by a
<select>
element. You just need to adapt your view model so that it has a property calledSelectedId
for example to which you will bind the dropdown:This assumes the following view model:
that will be handled by your controller: