1

問題は、ページネーションが 9 番目のページ番号まで正常に機能していることです。2 桁以上のページをリクエストすると、最後の桁が取得され、残りは無視されます。たとえば、ページ番号 10 をリクエストすると、 "?page=0" をクエリ文字列として渡すことでページ 0 を取得し、1 を破棄します。たとえば 458 などのページ番号を要求すると、"?page=8" をクエリ文字列として渡すことでページ番号 8 が表示され、45 が破棄されます。 458.これ が私のコードです:

Javacsript では:

        $(function () {
    $('tfoot a').click(function () {
        // try to extract the page number from the link
        var page = this.href.match(/page=([0-9])+/)[1];

        // submit the form so that the POST action is invoked
        var form = document.forms[0];
        form.action = '/Session/Index?page=' + page;
        form.submit();

        return false;
    });
});
      </script>

ビューで:

    var grid = new WebGrid(source: Model.ListSessions, rowsPerPage: 5,
    canPage: true, canSort: false, defaultSort: "Absentee");

     @grid.GetHtml(
    htmlAttributes: new { id = "grid" },
    tableStyle: "grid",
    headerStyle: "head",
    alternatingRowStyle: "alt",
    columns: grid.Columns(
                            grid.Column(format: @<text> <input type="hidden" id="ColorCodeValue" name="ColorCodeValue" value="@item.ColorCodeValue" /> </text>, style: "width:0px;"),
                            grid.Column("CreatedBy", "Created By"),
                            grid.Column("Session Title", format: (item) => Html.ActionLink((string)item.SessionTitle, MVC.Session.ActionNames.EditSession,
                            new { id = item.SessionId })),
                            grid.Column("SessionID", "Simple Session ID"),
                            grid.Column("StartDate", "Start Date"),
                            grid.Column("StartTime", "Start Time"),                               
                            grid.Column("SessionStatus", "Status"),
                            grid.Column("Prep Materials", format: @<text><a  onclick="SessionClick();" id="@item.EnableViewLink" href="@Url.Action(MVC.Session.Actions.ViewSession((string)item.SessionID))">View</a><a id="UploadSessionMaterial"  href="@Url.Action(MVC.Session.Actions.UploadSession((Int32)item.SessionId))">Upload</a>  </text>),
                            grid.Column("Action", format: @<text><a   href="@Url.Action(MVC.Session.Actions.ViewSession((int)item.SessionId))">View</a><a id="@item.IsPublished" class="@item.IsTranscriptExists" href="@Url.Action(MVC.Session.Actions.EditTranscript((Int32)item.SessionId))">Edited Session </a></text>)
                                     ), mode: WebGridPagerModes.All)

そしてコントローラーで:

    [HttpPost]
    public virtual ActionResult Index(SessionViewModel model)
    {
        model = GetSessionListing(model);
        return View(model);
    }


    private SessionViewModel GetSessionListing(SessionViewModel model)
    {
        if (model == null)
        {
            model = new SessionViewModel();
        }
        int page = 1;
        if (Convert.ToInt64( Request["page"]) != null)
            int.TryParse(Request["page"], out page);

        //Rest of Coding here           

        return model;
    }

どんな助けでも素晴らしいでしょう!さらに何か質問する必要がある場合は、私に質問してください。ありがとう!

4

2 に答える 2

1
// try to extract the page number from the link
var page = this.href.match(/page=([0-9])+/)[1];

正しい:

// try to extract the page number from the link
var page = this.href.match(/page=([0-9]+)/)[1];

「()」内に「+」が必要なのは、ここで実行しようとしているパターン グループではなく、一致パターンで「+」が必要だからです。

正規表現は常にトリッキーです!!

于 2013-05-20T06:03:39.753 に答える