I am creating an application in c# with mvc 2010 Express and I have one view with a drop down list to select a code. It redirects the user to another view (Filter
view) with another drop down list to select a market.
Then, depending on which code and market the user has selected, it displays a table of all the countries that exist for that code and market. (One market has many countries and there is at least one analysis (defined by a code) for each country per year).
I added a hidden element in my Filter
view:
@{
string code= ViewBag.code;
}
<script type="text/javascript">
$(function () {
$("#Market").change(function () {
var actionUrl = $('#TheForm1').attr('action') + '/' + $('#Market').val();
$('#TheForm1').attr('action', actionUrl);
$('#TheForm1').submit();
});
});
</script>
@using (Html.BeginForm("FilterAnMark", "Inform", FormMethod.Post, new { id = "TheForm1"})){
@Html.DropDownList("Market", (SelectList)ViewBag.mar, "Select a market")
@Html.Hidden("code", code)
}
Inform
Controller:
public ActionResult Filter(string id)
{
ViewBag.code = id;
var merc = from a in dre.v_AnalysisCountry
where a.Code == id
select a;
var query1 = merc.Select (a => new { a.Code,a.Market}).Distinct().OrderBy(a => a.Market);
ViewBag.mar = new SelectList(query1.AsEnumerable(), "Market", "Market");
return View();
}
public ActionResult FilterMarket(string id, string code)
{
var countries = new FilterManager().ObtainAnMarket(code, id);
return View(countries);
}
And then in this next view (FilterMarket
) I use a WebGrid
to display the countries:
@model IEnumerable<AlianzasIntranet.Models.DB.v_AnalysisCountry>
@{
WebGrid grid = new WebGrid(Model, defaultSort: "Market", rowsPerPage: 15);
}
@grid.GetHtml(
fillEmptyRows: true,
mode: WebGridPagerModes.All,
firstText: "<< First",
previousText: "< Previous",
nextText: "Next >",
lastText: "Last>>",
columns: new[] {
grid.Column("CountryName", style: "direc", header: "Country"),
... [etc]
})
The problem comes when the user tries to display another page of the table, as it displays a blank table because it doesn't remember this hidden element (the code
).
I think I should add it somewhere in my WegGrid but I don't know where.
I would be very grateful if you could help me. I really need to finish this. Thanks in advance!