0

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

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

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

看法:

            @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

2 回答 2

0

try this instead of html.beginform

 @using(Ajax.BeginForm(
new AjaxOptions{
HttpMethod="get",
InsertionMode=InsertionMode.Replace,
UpdateTargetId=""
}))
于 2013-09-19T12:48:22.240 回答
0

相反,您应该尝试:-查看:-

<% using (Html.BeginForm("EndUserSearch", "Search", **FormMethod.Get**))
{ %>
   // entire html page here
   // 

<%}

控制器:-

[httpGet]
public ActionResult Search(string Keywords, string sortBy = "SPName", bool ascending = true, int page = 1, int pageSize = 10)

{

}

每次您单击页码链接时,它都会带您进行搜索操作,您无需将页面发布到服务器上

于 2013-09-19T05:49:36.543 回答