0

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

例如,当我单击链接 2 时,我在 fire bug 中收到此错误:

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

或在链接 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)
4

0 回答 0