Within my view, there's a form representing my View model with multiple fields. I aim to generate a list of links for pagination purposes that will not only redirect to a specific page but also send the input data from the form along with it. The JavaScript snippet below showcases the function used to handle this functionality when bound to the page links as an OnClick action:
function SearchCriteria() {
this.OrderNumber = "";
this.CustomerNumber = "";
this.FirstName = "";
this.LastName = "";
this.Login = "";
this.Company = "";
this.Country = "";
}
function sendModel(page) {
var myModel = new SearchCriteria();
var PostData = JSON.stringify(myModel);
$.post('@Url.Action("ShowCustomers","Home")', PostData);
}
An issue arises where clicking on any of the page numbers results in no action. It seems like the script isn't being triggered at all.
The code responsible for binding the 'sendModel' function to the links is presented below:
<a class="@(i == ViewBag.CurrentPage ? "current" : "")" onclick="sendModel(@i)" href="#">@(innerContent ?? i.ToString())</a>
This particular piece of code is embedded within a loop designated for each respective page, hence why "i" correlates to the page corresponding to the link being generated.