2

我有一组记录,我在其中应用了 Entity Framework 中的 skip 和 take 参数。

所以在查询中我设置了参数常量,即 10。

我想在每次单击按钮时动态更改跳过参数。

这是我的代码。

 public ActionResult DateRecords()
    {
        if (!General.ValidateSession())
        {
            return RedirectToAction("Login", "User");
        }
        if (TempData["FromDate"] == null || TempData["toDate"] == null)
        {
            return View("InvalidDatesInput");
        }
        return View(this.GetRecordsByDate(0));
    }


    [HttpPost]
    public ActionResult DateRecords(int skipParam)
    {
        if (!General.ValidateSession())
        {
            return RedirectToAction("Login", "User");
        }
        return View(this.GetRecordsByDate(skipParam));
    }



public PassengerPaging GetRecordsByDate(int skipParam)
    {
        string fDate = TempData["FromDate"].ToString();
        string tDate = TempData["toDate"].ToString();
        TempData.Keep();
        PassengerPaging psngr = new PassengerPaging();
        psngr.Passengers = repository.GetRecords(fDate, tDate, skipParam).Select(x => new ViewModel.Passenger
        {
            ID = x.ID,
            Name = x.Name,
            FlightNo = FlightRepos.SelectByID(x.FlightId).FlightNo,
            Airline = airlineRepo.SelectByID(x.FlightId).Name,
            SeatNo = x.SeatNo,
            SequenceNo = x.SequenceNo,
            Date = x.Date,
            EnterBy = x.EnterBy,
            CheckinTime = x.CheckinTime,
            CheckoutTime = x.CheckoutTime,
            IsCheckout = x.IsCheckout
        }).ToList();

        psngr.Count = repository.GetRecordss(fDate, tDate).Count();
        psngr.skip = skipParam;
        return psngr;
    }

这是我的模型。

  public class PassengerPaging
    {
        [Key]
        //public int ID { get; set; }

        //public List<Passenger> Passengers { get; set; }
        //public int CurrentPageIndex { get; set; }
        //public int Count { get; set; }

        public int ID { get; set; }

        public List<Passenger> Passengers { get; set; }
        public int skip { get; set; }
        public int Count { get; set; }
    }

这是我的观点

<div>
    @using (Html.BeginForm("DateRecords", "PassengerInfo", FormMethod.Post))
    {
        <h2>All Records</h2>

        <div class="inner_page_about">
        </div>



        <br />
        <br />
        <div class="w3-row w3-border" style="width:100%">
            <div class="w3-container w3-half, col-md-4" >
                <input type="button" class="btn btn-outline-success" onclick="location.href='@Url.Action("ExportToExcel", "PassengerInfo")'" value="Export Detail Data" />
            </div>
            <div class="w3-container w3-half, col-md-4">
                <input type="button" class="btn btn-outline-success" onclick="showGraph(false)" value="Month wise Graph" />
            </div>
            <div class="w3-container w3-half, col-md-4">
                <input type="button" class="btn btn-outline-success" onclick="showGraph(true)" value="Date wise Graph" />
            </div>
        </div>

            <br />


            <hr />
            <table id="1">




                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Seat Number</th>
                        <th>Sequence Number</th>
                        <th>Airline</th>
                        <th>FLight Number</th>
                        <th>Date</th>
                        <th>CheckIn Time</th>
                        <th>Checkout Time</th>
                        <th>IsCheckout</th>
                        <th>Enter By</th>
                    </tr>
                </thead>
                @foreach (var item in Model.Passengers)
                {
                <tr>

                        <td>@item.Name</td>
                        <td>@item.SeatNo</td>
                        <td>@item.SequenceNo</td>
                        <td>@item.Airline</td>
                        <td>@item.FlightNo</td>
                        <td>@item.Date</td>
                        <td>@item.CheckinTime</td>
                        <td>@item.CheckoutTime</td>
                        <td>@item.IsCheckout</td>
                        <td>@item.EnterBy</td>
                    </tr>
                }

            </table>
            <br />
          <input type="button" id="1" value="next" onclick="PagerClick(@Model.skip)">
            <input type="hidden" id="hfCurrentPageIndex" name="skip" />
            @*<a href="/PassengerInfo/Submit/1"> <input type="Submit" class="btn btn-outline-success" value="FeedBack"></a>
            <a onclick="location.href='@Url.Action("CheckOutUpdate", "PassengerInfo", new { id = item.ID })'"> <input type="Submit" class="btn btn-outline-success" value="CheckOut"></a>
            <a href="/PassengerInfo/CheckOut#"> <input type="Submit" class="btn btn-outline-success" value="Update"></a>*@


            @*<td>

                <a href="/PassengerInfo/Submit/1"> <input type="Submit" class="btn btn-outline-success" value="FeedBack"></a>
                <a onclick="location.href='@Url.Action("CheckOutUpdate", "PassengerInfo", new { id = item.ID })'"> <input type="Submit" class="btn btn-outline-success" value="CheckOut"></a>
                <a href="/PassengerInfo/CheckOut#"> <input type="Submit" class="btn btn-outline-success" value="Update"></a>

            </td>*@


        <canvas id="graph" width="30" height="40" style="display:none"></canvas>
    }

    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.js"></script>
    <script type="text/javascript">
        debugger;
        function PagerClick(index) {
            document.getElementById("hfCurrentPageIndex").value = index;
            document.forms[0].submit();
        }

额外信息:这段代码运行良好,但问题是如果我的数据库中有 100 条记录,当我放置这种类型的逻辑时,它会显示 10 个按钮,但我只想要两个按钮

  • 下一个
  • 以前的

在每次点击时,我想在跳过参数上添加 +10,最初它是 0

并且每次单击上一个按钮时,我都想从跳过参数中获得-10。

4

0 回答 0