To limite page size, we only want to list a limited number of items at first. And then click Show More button to render more items. We can use partial view to reuse our code. In this example we will implement a simple task list.
Create show task action
Create PartialView _ShowTask.cshtml
In the list page, we can use Html.Action to show some items.
And then we implement an AJAX function for ‘Show More’ button.
We may want to implement an AJAX function to switch the status.
There are some tricks in this function:
we use $(document).on("click", ".switch", function () {}) instead of $(".switch").click(function() {}), so that all AJAX renderred switches can invoke the AJAX function as well.
We add context: this to change context to the switch button we click on. So we can change the style of the switch button inside the function.