【发布时间】:2023-03-15 22:47:01
【问题描述】:
我正在使用带有分页的 webgrid 的 MVC 应用程序。网格本身在名为 _Results.cshtml 的局部视图中呈现,并使用
在 index.cshtml 页面上的 div 中呈现Html.RenderPartial("_Results", Model.Results);
index.cshtml 上的部分网格以及其他一些表单控件被包装在一个名为 ResultsAction 的表单中,使用:
@using (Ajax.BeginForm("ResultsAction", "Results", new AjaxOptions.....
当最初导航到 index.cshtml 时,网格会按预期填充,并且将鼠标悬停在任何分页链接上都会正确显示:
http://localhost/ResultsAction?page=<page#>
网格中的每一行都有一个指向详细信息页面的链接。这可以按预期工作,并且详细信息页面有一个链接可以使用以下命令返回结果网格:
@Html.ActionLink("Return To Results", "Index", "Results")
现在的问题。这将我重定向回 Index.cshtml 就好了,但现在当我将鼠标悬停在网格中的任何分页链接上时,它们错误地使用:
http://localhost/Index?page=<page#>
这是错误的控制器操作,因此分页不再起作用。我的理解是分页链接应该使用表单名称作为操作发出 Get,但是当我导航到详细信息然后再次返回时,它会以某种方式被覆盖。有谁知道是什么导致了这种行为,或者我如何指定分页链接以始终使用相同的控制器操作?
编辑:按要求发布部分视图的代码:
@model IEnumerable<ispPR_GetInquiryRecords_Result>
@{
Layout = null;
}
<input id="searchListCnt" type="hidden" value="@Model.Count()" />
<div id="gridSearch">
@{
var grid = new WebGrid(selectionFieldName: "SelectedRow", canSort: false, canPage: true, rowsPerPage: 10, ajaxUpdateContainerId: "gridSearch");
var virtualCount = Model != null && Model.Count() > 0 ? Model.First().VirtualCount : 0;
grid.Bind(Model, rowCount: (int)virtualCount, autoSortAndPage: false);
}
<div id="gridContent">
@grid.GetHtml(
htmlAttributes: new { id = "inqgrid" },
tableStyle: "webGrid",
fillEmptyRows: false,
footerStyle: "gridFooter",
displayHeader: true,
alternatingRowStyle: "alt",
selectedRowStyle: "select",
mode: WebGridPagerModes.All,
columns: grid.Columns(
grid.Column("PriceStatus",header:"Price Status"),
grid.Column("CustomerName","Customer Name"),
grid.Column("EndUserName", "End User"),
grid.Column("ContractNumber","Contract"),
grid.Column("PriceLevel", "Level"),
grid.Column("ProductDescription", "Product Code"),
grid.Column(
header: "Break Qty",
format: @<text>@item.QuantityBreak.ToString() / @item.QuantityBreakUOM </text>
),
grid.Column("BeginDate", "Begin Date", format: item =>string.Format("{0:d}", item.BeginDate)),
grid.Column("EndDate","End Date",format: item =>string.Format("{0:d}", item.EndDate)),
grid.Column(
header: "Price in PricingUOM",
format: item =>
{
var res = Html.FormatToDecimals((decimal)item.PriceInPricingUOM, (int)item.Numdecimals);
switch ((bool)@item.HasDetail)
{
case true:
return Html.ActionLink(res + " / " + (string)item.PricingUOM, "InquiryDetails", new { @id = @item.PriceMasterID }, new { @class = "item-link2", @id = "lnk_" + @item.PriceMasterID });
case false:
return Html.ActionLink(res+ " / " + (string)item.PricingUOM, null, null, new { onclick = "return NoDetailsDialog('" + @item.NoDetailReason + "')" });
}
return null;
}
),
grid.Column(
header: "Price Alt UOM",
format: @<text>@Html.FormatToDecimals((decimal)item.PriceInOrderUOM, (int)item.Numdecimals) / @item.OrderUOM </text>
),
grid.Column("Rolling12", "Rolling 12 Sales", format: @<text>@String.Format("{0:c0}", @item.Rolling12) </text>),
grid.Column("CMPercent", "Net CM ", format: @<text>@String.Format("{0:0.00} %", @item.CMPercent * 100) </text>)
))
</div>
</div>
<script type="text/javascript">
function NoDetailsDialog(message) {
alert(message);
return false;
}
</script>
【问题讨论】:
-
可以发一下局部视图吗?
-
已发布。已编辑的问题。
-
WebGrid 给我带来了很多问题,我放弃了使用它。
-
有什么好的选择?
-
@AS2012 如果您有机会查看该问题,请告诉我?
标签: asp.net-mvc asp.net-mvc-4 asp.net-mvc-3 asp.net-mvc-5