Html表在页面加载时随机重复

时间:2017-09-22 06:39:38

标签: jquery html asp.net-mvc

我创建了一个MVC应用程序,除了页面加载问题外,它的工作正常。 我使用局部视图在我的页面上显示html表。我使用了分页,每页显示10条记录。

分页在所有页面上都正常工作,但在页面加载时,前10条记录正确显示,但在几分之一秒内,这10条记录会随机重复。

我已正确调试代码,但无法找到代码的任何问题。我已经在IE和Chrome中测试了该应用程序,但在页面加载时获得了相同的重复。

请帮助我知道可能的原因。 使用代码更新,删除了不必要的代码。 代码:

  • 控制器:

    [OutputCache(NoStore=true, Duration = 0)]
    public ActionResult Index()
         {
                try
                        {
                               List<FundVM> lst = GetAllFunds(1, 2);
                                return View(lst);
                         }
                catch (Exception ep)
                        {
                                 Logger.Error("Loging error---" + ep.StackTrace + "\n---------Message-----------\n" + ep.Message + "\n----------InnerException----------\n" + ep.InnerException);
                        }
                  return View();
                 }
    

public ActionResult GetFundList(int pageno,int pagesize)     {             尝试                 {                      List lst = service.GetAllFunds(pageno,pagesize);                      int count = lst.Count;

                 ViewBag.pageno = pageno;
                 ViewBag.pageSize = pagesize;

                 if (count < 1)
                    {
                          return Json(new { success = true, message = "You are on the last page" });

                     }
                     return View("PartialDataView", lst);
        }
        catch (Exception ep)
              {
                   Logger.Error("Loging error---" + ep.StackTrace + "\n---------Message-----------\n" + ep.Message + "\n----------InnerException----------\n" + ep.InnerException);
               }
        return View();
    }
  • GetAllFunds:

    public List<FundVM> GetAllFunds(int pageno, int pagesize)
               {
                        List<FUND> lst = new List<FUND>();
                        int startRecord = ((pageno - 1) * pagesize);
                        int endRecord = pagesize * pageno;
                        if (startRecord < 0)
                                  {
                                        //return 1;
                                   }
                          else
                                        {
                                            lst = (from mf in db.FUNDs
                   orderby mf.Id
                   select mf).Skip(startRecord).Take(pagesize).ToList();
                                          }
                              return ConvertListtoVM(lst);
    }
    
  • 用于分页的Jquery:

     function CallFundData(pageno) 
               {
                      var pagesize = 10;
                      $.ajax({
                              url: "/Fund/GetFundList",
                              data: { pageno: pageno, pagesize: pagesize },
                              type: "post",
                              success: function (res) {
                                     if (pageno < 1) 
                                               {
                                                  $('.#btnPrevious').disableSelection();
                    }
                    else if (res.success) 
                               {
                        $('.#btnNext').disableSelection();
    
                    }
                    else
                                  {
                                       $('#datadiv').html(res);
                                       $('#txtPageNo').val(pageno);
                                   }
                },
                               error: function ()
                                            {
                                                   alert("PageNo required");
                                              }
             });
        }
    
  • 查看:

调用部分视图:

<div id="datadiv">
        @Html.Partial("~/Views/Fund/PartialDataView.cshtml", Model)
</div>
  • 部分视图:

           <tbody>
                          @foreach (var mf in @Model)
                                      {
                                                <tr>
                                                   <td>@mf.Fee</td>
                                              </tr>
                                   }
            </tbody>
    

1 个答案:

答案 0 :(得分:0)

通过删除代码“@ Html.Partial(”〜/ Views / Fund / PartialDataView.cshtml“,Model)解决了这个问题” 查看并调用$(document).ready(function(){}中的CallFundData(1) Jquery。