在mvc4中进行分页而不刷新

时间:2013-09-21 10:01:11

标签: asp.net asp.net-mvc asp.net-mvc-4 asp.net-mvc-2

我想做一些这样的事情(<< 1 2 3 4>>)结束我的观点。我使用HTML.BeginForm并且它有效。但是我发布了回复。所以我将HTML.BeginForm更改为Ajax.BeginForm,现在它不起作用。

例如,当我点击链接2时,我在火灾中遇到此错误:

"  NetworkError: 500 Internal Server Error - http://localhost/myAction/search? numberpage=2"

或在linke 1上:

"  NetworkError: 500 Internal Server Error - http://localhost/myAction/search? numberpage=1"

观点:

         @using (Ajax.BeginForm( "search ","MyAction",new AjaxOptions
        {
            HttpMethod = "POST",
            InsertionMode = InsertionMode.Replace,
            UpdateTargetId = ""
        }))
        {
      int page = (int)ViewBag.page;
      int pages = (int)ViewBag.pages;

     <div class="pagination pagination-left">
    <ul>
        <li>@Ajax.ActionLink("«", "MyAction", new { numberpage = pages })</li>
        @{for (int i = pages; i >= 1; i--)
          {
              if (i == page)
              {
            <li class="active">@HtmlAjax.ActionLink(i.ToString(), " MyAction ",  new { numberpage = i })</li>
              }
              else
              {
            <li>@Ajax.ActionLink(i.ToString(), " MyAction ", new { numberpage =  i  })</li>
              }
          }
        }
        <li>@Ajax.ActionLink("»", " MyAction ", new { numberpage = 1 })</li>

    </ul>


</div>

我的控制员:

[HttpPOST]
   public ActionResult search(int? numberpage)
   {
    int skip = 0;
   ViewBag.page ;
  Temp= myobjectclass.GetAll().tolist();
   ViewBag.pages = (Temp.Count() / 5) + 1;

   var db = new ProjectContext();

   var obj = new projectClass.myobjectclass();
   if (numberpage!= null)
   {
       skip = 5 * (numberpage.Value - 1);
       ViewBag.page = numberpage.Value;

   }
   obj.StudentRequierments = Temp.Skip(skip).Take(5).ToList();
   ViewBag.pages = (Temp.Count() / 5) + 1;

   return View(obj)

0 个答案:

没有答案