Since you're trying to filter the displayed data in the grid, I'd do it this way:
In the main view I'd call a partial view
. In your case the partial view will hold the DropDownList
data. Something like this:
@Html.Partial("DropDownView", ViewBag.DropDownViewModel as DropDownViewModel)
In your controller action you'd fill the DropDownViewModel
with the DropDownList
data and would pass the DropDownViewModel
to the ViewBag
like this:
DropDownViewModel dropDownViewModel = new DropDownViewModel();
DropDownViewModel.Items = GetDropDownData(); // Fetch the items...
ViewBag.DropDownViewModel = dropDownViewModel;
ViewModel (DropDownViewModel.cs)
public class DropDownViewModel
{
public SelectList Items { get; set; }
}
Partial View (DropDownView.cshtml)
@model DropDownViewModel
@using (Html.BeginForm("YourControllerAction", "YourControllerName", FormMethod.Get))
{
@Html.Label("Search") @Html.DropDownList("YourDataId", Model.Items, String.Empty)
<input type="submit" value="Search" id="submit"/>
}
"YourDataId"
will be a parameter for the action method and will contain the value selected by the user like this:
public virtual ActionResult Index(int? YourDataId, GridSortOptions sort)
{
...
}