BriceTRockindale
BriceTRockindale

Reputation: 319

MVC 4 Dropdownlist form.submit pass in parameter value

I have this dropdown list that I would like it to post back, and pass the id to the controller. This code as it currently is will post back when I change the drop down, but as you can see, there is a hardcoded value of 3 that I am passing in. How do I get the SelectList value of the selected item to pass it to the controller?

@using (Html.BeginForm("Index", "PurchaseOrder", new { id = 3 }))
{
    @Html.DropDownList("jobStatuses", (SelectList)null, new { onchange = "this.form.submit();" })
}

Upvotes: 0

Views: 2785

Answers (1)

Slicksim
Slicksim

Reputation: 7172

I would do it like this:

@using (Html.BeginForm("Index", "PurchaseOrder", new { id = "" }))
{
    @Html.DropDownList("id", (SelectList)null, new { onchange =  "this.form.submit();" })
}

Changing the name of the control to id will pass it through to the id parameter of the controller action

Upvotes: 2

Related Questions