Reputation: 37
I have a drop down list in Razor View
@Html.DropDownList("ddlAccount", items)
this drop down list is binded with items.
I want to pass this selected list item to 'Create' Method of "TaskManagement" Controller on click of action link.
@Html.ActionLink("Create New Task", "Create", "KTTaskManagement")
Upvotes: 2
Views: 3625
Reputation: 17554
And while your at it please use the typed equivalence
@Html.DropDownListFor(m => m.SelectedItemId, new
SelectList(Model.Items, "ItemId", "ItemName", Model.SelectedItemId))
Upvotes: 0
Reputation: 1038940
The semantically correct way to handle this case is to use a form instead of an anchor:
@using (Html.BeginForm("Create", "KTTaskManagement"))
{
@Html.DropDownList("ddlAccount", items)
<button type="submit">Create New Task</button>
}
This way the selected value of the dropdown will be automatically sent to the controller action:
public ActionResult Create(string ddlAccount)
{
// the action argument will contain the selected value
...
}
Upvotes: 1