I have a page with 2 dropdownlist. one country, one currency and depend on country I want to fill currency dropdownlist and after click button I want to fill the grid from database. I simplfied my code to show what I have tried. What is the best and easist approach?
public ActionResult ddlCountry()
{
var countryList = new List<string>();
countryList.Add("US");
countryList.Add("GB");
return View(countryList);
}
public ActionResult ddlCurrency(string country)
{
var curencyList = new List<string>();
if(country == "US")
curencyList.Add("USD");
if(country == "GB")
curencyList.Add("GBP");
return View(curencyList);
}
public ActionResult Index(string country, string currency)
{
var viewModels = new List<FooViewModel>();
//code gets values from database
return View(viewModels);
}
<div>
@using (Html.BeginForm())
{
<table>
<tr>
<td>Country</td>
<td>@Html.DropDownListFor(model => model.SelectedId, new SelectList(Model.Choices, "Id", "Text"), "Choose... ")</td>
<td>Currency</td>
<td>@Html.DropDownListFor(model => model.SelectedId, new SelectList(Model.Choices, "Id", "Text"), "Choose... ")</td>
</tr>
</table>
@Html.ActionLink("Search", "Index", new {})
}
</div>
@using (Html.BeginForm("Search", "Index", new { Country = "IN", Currency = "INR" }, FormMethod.Post, new { id = "foo" }))
{
<div>
@Html.Grid(Model).Named("valueGrid").Columns(columns =>
{
columns.Add(vm => vm.Country).Titled("Country");
columns.Add(vm => vm.Currency).Titled("Currency");
columns.Add(vm => vm.Value).Titled("Value");
}).WithPaging(25).Sortable(true).Filterable(true)
</div>
}