I'm not getting paging on my Grid with Jquery

0

When I click on Next and Previous does not change page and remains only on the Index page, I already tested Jquery made an Alert and the two buttons are working, but it does not change the page and there are no errors in my application.

public class HomeController : Controller
{
    private CadastroGeralEntities _Context = new CadastroGeralEntities();

    public ActionResult Index()
    {
        ViewBag.CurrentPage = 1;
        return View(_Context.Empregadoes.Take(5));
    }

    [HttpPost]
    public ActionResult Index(int CurrentPage)
    {
        ViewBag.CurrentPage = CurrentPage;

        return View(_Context.Empregadoes.OrderBy(c=>c.EmpregadoID).Skip((CurrentPage - 1) * 5).Take(5)); 
    }

    public ActionResult Add()
    {
        return View();
    }

Index -----------------

  <div>
      @using(Html.BeginForm())
    {
        <input type="hidden" id="CurrentPage" name="CurrentPage" value="@ViewBag.CurrentPage" />
    }

    <input type="button" id="Previous" name="Previous" value="Previous" />
    <input type="button" id="Next" name="Next" value="Next" />

</div>

<script type="text/javascript">
$(document).ready(function () {
    $("#Previous").click(function () {

        if (CalculateAndPage("Previous"))
            $('form').submit();
    });

    $("#Next").click(function () {
        if (CalculateAndPage("Next"))
            $("form").submit();

    });
});

function CalculateAndPage(movingType) {

    var currentPage = parseInt($("#CurrentPage").val());

    if (currentPage == 1 && movingType == "Previous")
        return false;

    if (movingType == "Previous") {
        currentPage--;
    }
    else if (movingType == "Next") {
        currentPage++;
    } else

        alert("Algo Errado");

    $("CurrentPage").val(currentPage);
    return true;
}
    
asked by anonymous 15.06.2018 / 00:01

0 answers