MVC 3 RC2 Webgrid 噩梦,有人让分页正常工作吗?

发布于 2024-10-07 05:18:49 字数 1488 浏览 3 评论 0原文

我正在使用 MVC3 的最新 RC2 版本。

我有一个网络网格,它给我带来了可怕的问题,特别是在分页和排序方面。 有人告诉我,分页现在应该更有效,而不是拉回整个表,而只拉回您正在查看的页面所需的行。这并没有像我希望的那样工作(非常慢),因此将其采用最简单的形式并启动了分析器。

我有这个 ActionResult:

    public ActionResult TestGrid()
    {
        return View(ents.Decisions);
    }

并且这个视图:

    @model IEnumerable<DecisionPanel.Web.Models.DataModel.Decision>

@{
    ViewBag.Title = "TestGrid";
    var usersGrid = new WebGrid(source: Model, rowsPerPage: 50);
}

<h2>TestGrid</h2>

@usersGrid.GetHtml(
        tableStyle: "grid",
        headerStyle: "header",
        alternatingRowStyle: "alt",
        rowStyle: "row",
                columns: usersGrid.Columns(
                        usersGrid.Column("UserID", "User Id"),
                        usersGrid.Column("HasAgreed", "Has Agreed?"),
                        usersGrid.Column("Comment"),
                        usersGrid.Column("DateResponded", "Date of Response", format: @<text>@item.DateResponded.ToString("dd MMM yyy (HH:mm.ss)")</text>)
        )
    )

点击页面导致它在分析器上运行 - 11 次

SELECT 
[Extent1].[ID] AS [ID], 
[Extent1].[UserID] AS [UserID], 
[Extent1].[HasAgreed] AS [HasAgreed], 
[Extent1].[Comment] AS [Comment], 
[Extent1].[DateResponded] AS [DateResponded]
FROM [dbo].[DecisionResults] AS [Extent1]

我遇到了一些其他问题,但如果我什至无法让这个工作我正在考虑放弃网络网格。

我知道现在还为时过早,它发布还不到一周,但是还有其他人在使用寻呼时感到高兴吗?

I am using the latest RC2 version of MVC3.

I have a webgrid and it is giving me horrible problems, specifically with the paging and sorting.
I have been told that the paging should be more efficient now, and not pull back the whole table but only rows needed for the page you are viewing. This is not working as i hoped (very slow), and so have taken it to the simplest form and booted up the profiler.

I have this ActionResult:

    public ActionResult TestGrid()
    {
        return View(ents.Decisions);
    }

And this view:

    @model IEnumerable<DecisionPanel.Web.Models.DataModel.Decision>

@{
    ViewBag.Title = "TestGrid";
    var usersGrid = new WebGrid(source: Model, rowsPerPage: 50);
}

<h2>TestGrid</h2>

@usersGrid.GetHtml(
        tableStyle: "grid",
        headerStyle: "header",
        alternatingRowStyle: "alt",
        rowStyle: "row",
                columns: usersGrid.Columns(
                        usersGrid.Column("UserID", "User Id"),
                        usersGrid.Column("HasAgreed", "Has Agreed?"),
                        usersGrid.Column("Comment"),
                        usersGrid.Column("DateResponded", "Date of Response", format: @<text>@item.DateResponded.ToString("dd MMM yyy (HH:mm.ss)")</text>)
        )
    )

Hitting the page is causing this to run on the profiler - 11 times:

SELECT 
[Extent1].[ID] AS [ID], 
[Extent1].[UserID] AS [UserID], 
[Extent1].[HasAgreed] AS [HasAgreed], 
[Extent1].[Comment] AS [Comment], 
[Extent1].[DateResponded] AS [DateResponded]
FROM [dbo].[DecisionResults] AS [Extent1]

I am having some other problems but if i can't even get this working i am considering abandoning the webgrid.

I know it's early days with it being out under a week, but has anyone else had any joy using the paging?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

路还长,别太狂 2024-10-14 05:18:49

此时,我可以确认 MVC3 RC2 中的 WebGrid 存在问题,它无法智能地处理支持数据库端分页的 IQueryable 数据。我们将研究为 RTM 解决此问题。现在您必须手动进行分页。对此感到抱歉。

At this point I can confirm there is an issue with the WebGrid as shipping in MVC3 RC2 where it does not smartly handle IQueryable data that supports database-side paging. We'll look into resolving this for RTM. For now you would have to do paging manually. Sorry about that.

千柳 2024-10-14 05:18:49

你不应该指定类似的寻呼机吗

@usersGrid.Pager(WebGridPagerModes.NextPrevious)

Aren't you supposed to specify the pager similar to

@usersGrid.Pager(WebGridPagerModes.NextPrevious)
挽容 2024-10-14 05:18:49

有点搞乱了 IQueryables 仍然不受支持。我使用 PagedList 类控制器代码解决了这个问题

public class PagedList<T> : List<T>
{
    int _pageNr;
    int _pageSize;
    string _orderByCol;
    bool _asc;
    IQueryable<T> _query;

    public PagedList(int pageNumber, int pageSize, string orderBy, string direction, IQueryable<T> list)
    {
        var query = list;
        _query = list;
        if (!string.IsNullOrEmpty(orderBy))
        {
            if (!string.IsNullOrEmpty(direction))
            {
                orderBy = orderBy + " " + direction;
            }

            query = query.OrderBy(orderBy);
        }
        query = query.Skip(pageNumber * pageSize).Take(pageSize);
        this.AddRange(query.ToList());
    }

    public int Count 
    {
        get {
            return _query.Count();
        }
    }
}

    public ActionResult Index(int page = 1, int pageSize = 2, string sort = null, string sortDir = "ASC")
    {
        return View(new PagedList<Something>(page-1, pageSize, sort, sortDir, Client.RetrieveAll<Something>()));
    }

根据我的观点:

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
  <div>
    <%

        var grid = new WebGrid(rowsPerPage: 2);
       grid.Bind(
           Model,
           autoSortAndPage: false,
           rowCount: Model.Count
           );
       %>
    <%:
        grid.GetHtml()
    %>
  </div>
</asp:Content>

Kinda messed up that IQueryables are still not supported. I worked around it using a PagedList class

public class PagedList<T> : List<T>
{
    int _pageNr;
    int _pageSize;
    string _orderByCol;
    bool _asc;
    IQueryable<T> _query;

    public PagedList(int pageNumber, int pageSize, string orderBy, string direction, IQueryable<T> list)
    {
        var query = list;
        _query = list;
        if (!string.IsNullOrEmpty(orderBy))
        {
            if (!string.IsNullOrEmpty(direction))
            {
                orderBy = orderBy + " " + direction;
            }

            query = query.OrderBy(orderBy);
        }
        query = query.Skip(pageNumber * pageSize).Take(pageSize);
        this.AddRange(query.ToList());
    }

    public int Count 
    {
        get {
            return _query.Count();
        }
    }
}

Controller Code :

    public ActionResult Index(int page = 1, int pageSize = 2, string sort = null, string sortDir = "ASC")
    {
        return View(new PagedList<Something>(page-1, pageSize, sort, sortDir, Client.RetrieveAll<Something>()));
    }

With my view:

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
  <div>
    <%

        var grid = new WebGrid(rowsPerPage: 2);
       grid.Bind(
           Model,
           autoSortAndPage: false,
           rowCount: Model.Count
           );
       %>
    <%:
        grid.GetHtml()
    %>
  </div>
</asp:Content>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文