0

I am trying to generate enough pagination links accordingly to amount of job offers. (I am building something related to job searching).

I am trying to call Send function after click event but I have another jQuery targeting that list.

<li class="active page-number"><a href="#" onclick="Send(2)">2</a></li>

<script>
    ///Custom scripts
    ///
    function Send(page) {
       $.post("/JobOffer/JobList/", { page: page });
    }

    $(document).ready(function () {
        $(".pagination>li").click(function () {
            $(".pagination>li.active").removeClass("active");
            $(this).addClass("active");
        });
    });
</script>

So when I click on ".pagination>li" I go to Action JobList in JobOffer controller marked with [HttpPost].

  [HttpPost]
  public ActionResult JobList(int? page)
  {
        var pageNumber = page ?? 1;
        var pageSize = 3;

        /*Some magic*/

        viewModel.OfferCount = GetJobOfferCount(Enums.JobOfferType.Employer);
        viewModel.PageSize = pageSize;

        return View(viewModel);
  }

And then I receive page parameter as null.

How could I send page parameter to my action method? Thanks in advance.

1 Answer 1

1

Try using the @Url.Action() helper with the overload that takes Action and Controller name. And modify your html to take advantage of the data-attribute. Just a simplified solution of your problem. Try this:

<li class="active page-number"><a href="#" data-page="2">2</a></li>

$(document).ready(function () {

    $("a").click(function () {
        var page = $(this).data("page");            
        $.post("@Url.Action("JobList","JobOffer")", { page: page });

        $(this).parent().toggleClass("active");
    });


});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.