0

我正在使用mvc 2010 Express在c#中创建一个应用程序,并且我有一个带有下拉列表的视图来选择代码。它使用另一个下拉列表将用户重定向到另一个视图(视图)以选择市场。Filter

然后,根据用户选择的代码和市场,它会显示该代码和市场存在的所有国家/地区的表格。(一个市场有许多国家,每年每个国家至少有一个分析(由代码定义))。

我在视图 中添加了一个隐藏元素:Filter

@{
    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控制器:

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);
}

然后在下一个视图 ( FilterMarket) 中,我使用 aWebGrid来显示国家/地区:

@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]
})

当用户尝试显示表格的另一页时,问题就出现了,因为它显示了一个空白表格,因为它不记得这个隐藏元素()。我想我应该在我的 WegGrid 的某个地方添加它,但我不知道在哪里。code

如果您能帮助我,我将不胜感激。我真的需要完成这个。提前致谢!

4

1 回答 1

0

Controller在中间创建一个中间 ActionResultFilterFilterMarket解决问题。它将从 that中获得IdAnalysisand 然后在FilterMarketandCode中: MarketIdAnalysis

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 IntermFilter(string id, string code)
{
    int idFirstAn = (from m in dre.v_AnalysisCountry
                     where m.Code == code && m.Market == id
                     select m.IdAnalysis).FirstOrDefault();
    return RedirectToAction("FilterMarket", new { id = idFirstAn });
}

public ActionResult FilterMarket(int id)
{
    var query = (from m in dre.v_AnalysisCountry
                 where m.IdAnalysis == id
                 select m).FirstOrDefault();
    var countries = new FilterManager().ObtainAnMarket(query.Code, query.Market);
    return View(countries);
}
于 2013-09-10T10:38:07.617 回答