如何在查询中单击按钮时设置跳过参数?

时间:2018-04-07 04:47:41

标签: javascript c# asp.net 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来自跳过参数。

0 个答案:

没有答案