我正在使用MVCGrid.net (http://mvcgrid.net)。首先,神奇的网格工具!我的网格正常工作,但是在填充网格时,我需要向我的RetrieveDataMethod传递一个附加参数。我需要传递的值是我的视图模型的一部分,我非常确定我需要将它作为一个AdditionalQueryOption传递。我不想让它成为一个过滤器,因为我不希望它只在客户端事件之后发送。我希望它永远传递给我的RetrieveDataMethod。我尝试向我的隐藏输入中添加数据-mvcgrid-type=‘additionalQueryOption’,但它仍然没有发送。然后,我注意到这需要数据-mvcgrid-apply-附加=‘event’来触发事件。这和过滤器有什么不同?是否有一个网格加载事件,我可以挂钩,以注册我的隐藏值作为一个额外的查询选项?对我的处境有什么正确的处理方法?
下面是我的网格的检索数据方法定义:
.WithRetrieveDataMethod((context) =>
{
var options = context.QueryOptions;
// this is the bit i need
var projectId = ???;
options.AdditionalQueryOptions.Add("projectId", projectId);
int totalRecords;
var items = ReportManager.GetReports(out totalRecords, options);
return new QueryResult<ReportSummaryViewModel>()
{
Items = items,
TotalRecords = totalRecords
};
})这是视图代码:
<h1>Reports for @Model.ProjectName</h1>
<p class="form-inline">
<button type="button" class="btn btn-default" onclick="window.location.href='@Url.Action("Index", "Home")'">Back</button>
<button type="button" class="btn btn-primary" onclick="window.location.href='@Url.Action("Create", "Reports", new { @id = Model.ProjectId })'">New Report</button>
</p>
<!-- This is the hidden input i'd like to pass as an additional query option-->
@Html.HiddenFor(x => x.ProjectId)
<div id="reportList">
@Html.MVCGrid("ReportsGrid")
</div>我需要的附加选项作为查询字符串参数传递。因此,我尝试在document上设置额外的查询选项。
$(function () {
initAdditionalOptions();
});
function initAdditionalOptions() {
MVCGrid.setAdditionalQueryOptions("ReportsGrid", { projectId: $('#ProjectId').val() });
}这在技术上是可行的,但是id现在在url中两次: /Reports/Index/21?projectid=21
我可以接受,但这里有更好的方法吗?
发布于 2015-05-06 14:34:30
最近添加了一个名为Page参数的新特性来完成您想要做的事情。确保您使用的是最新的NuGet包。
下面是如何使用它:
1)将其添加到网格配置中:
.WithPageParameterNames("ProjectId")
2)从视图传入参数的值。
@Html.MVCGrid("PPGrid", new { ProjectId = "whatever" })
3)使用RetrieveDataMethod中的值
string projectIdVal = context.QueryOptions.GetPageParameterString("ProjectId");
https://stackoverflow.com/questions/30044391
复制相似问题