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

Javascript 如何在查询中的按钮单击上设置跳过参数?,javascript,c#,asp.net,skip-take,Javascript,C#,Asp.net,Skip Take,我有一组在实体框架中应用skip和take参数的记录 所以在查询中,我设置了take参数常量,即10 我想在每次单击按钮时动态更改跳过参数 这是我的密码 public ActionResult DateRecords() { if (!General.ValidateSession()) { return RedirectToAction("Login", "User"); } if (TempDa

我有一组在实体框架中应用skip和take参数的记录

所以在查询中,我设置了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; }
    }
公共类密码
{
[关键]
//公共int ID{get;set;}
//公共列表乘客{get;set;}
//public int CurrentPageIndex{get;set;}
//公共整数计数{get;set;}
公共int ID{get;set;}
公共列表乘客{get;set;}
公共整数跳过{get;set;}
公共整数计数{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();
        }

@使用(Html.BeginForm(“DateRecords”,“PassengerInfo”,FormMethod.Post))
{
所有记录




名称 座位号 序列号 航空公司 航班号 日期 登记时间 结帐时间 伊斯切科特 进入 @foreach(乘客模型中的var项目) { @项目名称 @项目1.SeatNo @项目编号 @项目.航空公司 @项目.航班号 @项目.日期 @item.CheckinTime @项目.签出时间 @item.IsCheckout @项目.输入 }
@* *@ @* *@ } 调试器; 功能页面单击(索引){ document.getElementById(“hfCurrentPageIndex”)。值=索引; document.forms[0]。提交(); }
额外信息:这段代码运行良好,但问题是,如果我的数据库中有100条记录,当我输入这种逻辑时,它会显示10个按钮,但我只需要两个按钮

  • 下一个
  • 先前的
每次单击时,我想在skip参数上添加+10,初始值为0


每次单击上一个按钮,我都想从skip参数中得到-10。

只需将其保留在viewdata或sessionidn中就可以了。将skip值保留在viewdata或session中,并为每个按钮单击serverside$(“#myid”)。单击(function(){document.getElementById(“hfCurrentPageIndex”).value=@Model.skip+10;document.forms[0].submit();我已经在按钮上调用了此函数,这解决了我的问题。谢谢你的建议