当我点击webGrid中的下一页时,我得到一个传递给我的Action方法的空值,我不明白为什么。当我执行原始POST时,值就在那里。
这是我的控制器页面:
public ActionResult Index()
{
return View();
}
public ActionResult Results()
{
string year = Request.Form["testCriteria.Year"];
List<TestCriteriaResults> test = new List<TestCriteriaResults>();
test.Add(new TestCriteriaResults { Value1 = "one", Value2 = "one", Value3="three", Value4="Four" });
test.Add(new TestCriteriaResults { Value1 = "one", Value2 = "two", Value3="three", Value4="four" });
test.Add(new TestCriteriaResults { Value1 = "one", Value2 = "two", Value3 = "three", Value4 = "four" });
test.Add(new TestCriteriaResults { Value1 = "one", Value2 = "two", Value3 = "three", Value4 = "four" });
test.Add(new TestCriteriaResults { Value1 = "one", Value2 = "two", Value3 = "three", Value4 = "four" });
TestCriteriaConsolidated combined = new TestCriteriaConsolidated();
combined.testCriteriaResults = test;
return PartialView(combined);
}
这是部分视图,我在点击分页时尝试获取'年'
@model MvcApplication1.Models.TestCriteriaConsolidated
@using (Html.BeginForm("Results", "Home"))
{
<div style="float:left">
<div style="font-weight:bold">
@Html.LabelFor(m => m.testCriteria.Year)
</div>
<div style="width:110px; ">
@Html.DropDownListFor(m => m.testCriteria.Year, new SelectList(new[]
{
new SelectListItem{ Text="All Years", Value=" " },
new SelectListItem{ Text="2010", Value="2010" },
new SelectListItem{ Text="2009", Value="2009" },
new SelectListItem{ Text="2008", Value="2008" },
new SelectListItem{ Text="2007", Value="2007" },
new SelectListItem{ Text="2006", Value="2006" }
}, "Value", "Text", "1"), new { @style = "width: 100px; margin-top: 5px" })
</div>
</div>
<div style="float:left">
<div>
</div>
<div style="width:100px; ">
<input type="submit" value="Results" />
</div>
</div>
}
这是我的WebGrid代码:
@model MvcApplication1.Models.TestCriteriaConsolidated
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@if(Model.testCriteriaResults.Count() > 0)
{
var grid = new WebGrid(Model.testCriteriaResults,canPage: true, rowsPerPage: 2);
@grid.Pager(WebGridPagerModes.Numeric);
<div id="grid">
@grid.GetHtml()
</div>
}