In my ASP.NET Core app, I have this customer view:
I have divided the view into Part 1 and Part 2. Actually I need to achieve these 2 things in ASP.NET Core MVC:
When the user clicks the Search button, load the Part 2 component.
When the user clicks pagination in part 2, I need to refresh only part 2 component.
I have decided do the part 1 as a Razor view and Part 2 as a view component. Also I want to achieve refreshing the component when the user clicks Search button (part1) and clicks the pagination (inside same component)
- Please let me know whether I did correct or not?
- How to send the page index to component to reload the the component with ajax when page index is clicked?
Thanks in advance. I don't expect entire code. Please let me know the logic to refresh the component.
This is the code for pagination.
<nav aria-label="Pagination" class="col-12">
<ul class="pagination justify-content-end">
<li class="page-item @prevDisabled">
<a class="page-link"
asp-controller="Home" asp-action="getcust"
asp-route-id="@(Model.Stocks.PageIndex - 1)"
aria-label="Previous">
<span aria-hidden="true">«</span>
<span class="sr-only">Previous</span>
</a>
</li>
@foreach (var i in Model.Stocks.PageIndexesToDisplay)
{
var activeClass = i.IsActive ? "active" : "";
<li class="page-item @activeClass"><a class="page-link"
asp-controller="Home" asp-action="getcust"
asp-route-id="@(i.Index)">@i.Index</a></li>
}
<li class="page-item @nextDisabled">
<a class="page-link"
asp-controller="Home" asp-controller="Home" asp-action="getcust"
asp-route-Id="@(Model.Stocks.PageIndex + 1)"
aria-label="Next">
<span aria-hidden="true">»</span>
<span class="sr-only">Next</span>
</a>
</li>
</ul>
</nav>
