Click here to Skip to main content
15,914,594 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i wanna make some thing like this ( << 1 2 3 4 >> ) end of my view . i used HTML.BeginForm and it worked .but i had post back.so i changed HTML.BeginForm to Ajax.BeginForm , now it dose not work

for example when i click on link 2 i get this error in fire bug
C#
"  NetworkError: 500 Internal Server Error - http://localhost/myAction/search? pagenumber=2"


view:

JavaScript
     @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>


controller :

C#
[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);
Posted
Updated 20-Sep-13 20:25pm
v5

1 solution

Please change the attribute HttpPost to HttpGet and then try
C#
[HttpGet]
   public ActionResult search(int? numberpage)

Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900