【问题标题】:Webgrid with filtered results带有过滤结果的 Webgrid
【发布时间】:2011-09-04 14:39:32
【问题描述】:

我喜欢 Razor-ViewEngine 中的 Webgrid HTML-Helper。

很遗憾,我遇到了问题。使用内置的排序和分页功能,我失去了我的过滤器设置。

在网格上方我有一个过滤器控件(表单),通过填充过滤器类并在提交时调用控制器上的操作方法来过滤网格中显示的行。

控制器中的代码:

public ActionResult DeliveryContractList(SampleClassFilter filter){

   // Populate a filtered List of Items to Show    
   IList<SampleClass> model = FillList(filter);

   // Return a View with the List.
   return View("SampleClassList", model);

}

观点:

  @model IEnumerable<SampleClass>
  @{
      ViewBag.Title = "SampleClassList";
  }

  @using(Html.BeginForm()){
        // Form to Set the Filter
        ...
  }

  <div id = "SampleClassList">

    var grid = new WebGrid(Model, canPage: true, canSort: true, ajaxUpdateContainerId: "SampleClassList");

    @grid.GetHtml(htmlAttributes: new {id = "gridSampleClass"}, columns:
        grid.Columns(
            grid.Column("Foo", "For", canSort: true),
            grid.Column("Bar", "Bar", canSort: true),
        )
     ); 
</div>

我在点击例如用于对控制器中的操作方法进行排序的网格的列标题也被调用。当然,过滤器类为 null 会导致未过滤的结果集。

有没有办法在对 webgrid 进行排序或分页时过滤我的结果? 我不想用jquery!!!

提前致谢 托比


是否可以定义添加到单击排序或页面链接时调用的链接的参数?

【问题讨论】:

  • 我下面的回答有问题吗?
  • 有人有答案吗??

标签: asp.net-mvc-3 razor html-helper webgrid


【解决方案1】:

啊哈。问题是您需要在过滤器字段和 Web 网格周围添加一个 GET 表单。然后你需要对 webgrid 数据做一点点按摩,以便它以它识别的方式发布它的排序信息。我丢失了我读到的文章的链接,但我在这里有一个例子:ASP.NET MVC3 WebGrid - custom, server-side sorting

您最终会得到类似 localhost/example/admin/thing?thingName=Hyatt&City=&State=TX&Country=&sort=city&sortdir=ASC 之类的网址

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-14
    • 2011-06-28
    • 2015-02-04
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 2020-10-20
    • 2012-01-12
    相关资源
    最近更新 更多