我有以下代码,我有一个如下所示的页面:
我希望能够选择每页的行数,但我不断收到错误消息: “CS1502:最好的重载方法匹配'System.Web.Helpers.WebGrid.WebGrid(System.Collections.Generic.IEnumerable,System.Collections.Generic.IEnumerable,string,int,bool,bool,string,string,string, string,string,string,string)'有一些无效的参数“
当var rpp = data.Count()时,网格1实际上采用了@rpp的剃刀语法,但是当我在网格2中使用@rpp并使var rpp = Request [“rpp1']时,它没有接受它并且它给了我那个错误。有什么方法可以避免这个吗?
@{
if(Request["action"] == "Go")
{
var rpp = Request["rpp1"];
<p>Showing @rpp rows per page.</p>
var columns2 = new[]{"ID", "SSO", "Category", "System", "Subject", "Created", "Assigned_To", "Case_Status"};
var grid2 = new WebGrid(data, ajaxUpdateContainerId: "grid", defaultSort: "ID", columnNames: columns2, rowsPerPage: @rpp);
if (Request.QueryString[grid.SortDirectionFieldName].IsEmpty()) {
grid2.SortDirection = SortDirection.Descending;
}
@grid2.GetHtml(
tableStyle : "table",
alternatingRowStyle : "alternate",
headerStyle : "header",
mode: WebGridPagerModes. All,
previousText: "Previous",
nextText: "Next",
firstText: "First Page",
lastText: "Last Page",
columns: grid.Columns(
grid.Column("ID", "ID"),
grid.Column("SSO", "SSO"),
grid.Column("Category", "Category"),
grid.Column("System", "System"),
grid.Column("Subject", "Subject"),
grid.Column("Created", "Created"),
grid.Column("Assigned_To", "Assigned To"),
grid.Column("Case_Status", "Status")
)
)
} else{
if(Request["action"] == "Plain Table - Excel")
{
var rpp = data.Count();
var columns1 = new[]{"ID", "SSO", "Category", "System", "Subject", "Created", "Assigned_To", "Case_Status"};
var grid1 = new WebGrid(data, ajaxUpdateContainerId: "grid", defaultSort: "ID", columnNames: columns1, rowsPerPage: @rpp);
if (Request.QueryString[grid1.SortDirectionFieldName].IsEmpty()) {
grid1.SortDirection = SortDirection.Descending;
}
@grid1.GetHtml(
mode: WebGridPagerModes. All,
columns: grid.Columns(
grid.Column("ID", "ID"),
grid.Column("SSO", "SSO"),
grid.Column("Category", "Category"),
grid.Column("System", "System"),
grid.Column("Subject", "Subject"),
grid.Column("Created", "Created"),
grid.Column("Assigned_To", "Assigned To"),
grid.Column("Case_Status", "Status")
)
)
} else .............
这是表格:
<h4>Rows Per Page</h4>
<form action="" method="get">
<div class="right">
<select id="rpp1" name="rpp1">
<option selected="@(Request["rpp1"] == "15")" value="15">15</option>
<option selected="@(Request["rpp1"] == "25")" value="25">25</option>
<option selected="@(Request["rpp1"] == "50")" value="50">50</option>
<option selected="@(Request["rpp1"] == "75")" value="75">75</option>
<option selected="@(Request["rpp1"] == "100")" value="100">100</option>
</select>
</div>
<input type="submit" name="action" value="Go"/>
</form>
答案 0 :(得分:1)
正如错误消息告诉您的那样,错误的数据类型作为参数传递给WebGrid构造函数。请求项是字符串,而不是整数。您可以使用AsInt()扩展方法来更改它:
var rpp = Request["rpp1"].AsInt();
此外,在代码块内部不需要@符号:
var grid2 = new WebGrid(data, ajaxUpdateContainerId: "grid", defaultSort: "ID", columnNames: columns2, rowsPerPage: rpp);