在制作中省略回发(<<< 1 2 3 4>>)

时间:2013-09-19 05:10:38

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

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

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

    "  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);

2 个答案:

答案 0 :(得分: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)

{

}

每当您点击页码链接时,它将带您进行搜索操作,而您无需将您的页面发布到服务器上

答案 1 :(得分:0)

试试这个而不是html.beginform

 @using(Ajax.BeginForm(
new AjaxOptions{
HttpMethod="get",
InsertionMode=InsertionMode.Replace,
UpdateTargetId=""
}))