Comments (6)
@CybrZr00 HI, thank you for your feedback. Actually, the pager tag will append page={0}
as the href
attribute of the <a>
element. The AJAX feature is enabled when data-ajax
attribute is set on the element when you introduced the Microsoft Unobtrusive Ajax library.
It is important to know that AJAX is not provided by the <pager>
tag. It ONLY helps you to add data-ajax
related attributes on link elements, and the Unobtrusive Ajax library will search for these tags and then add event handler on them to enable the AJAX behavior. In another words, you may try to put <a>
tag in your page with data-ajax="true"
set on it, and you may test if the AJAX feature is correctly enabled, and then, you should check the generated final HTML code from <pager>
tag has the same AJAX related settings, which means the links inside the pager are also AJAX enabled.
Hope the above message is helpful, and please feel free to reply if you have any new question :-)
from aspnetcore.
Ah yes thats probably the issue, I needed to add the extra attributes, or at least some initial defaults. As a work around I used the old way (Obtrusive?) for the initial ajax call in a $(document).ready, which then updated the pager for me, as I was unable to get the setting-link-attr-asp-action="" and setting-link-attr-asp-route-perPage="" to work.
from aspnetcore.
@CybrZr00 Hi, I'm not quite clear about your detailed design, could you please show a minimal example to reproduce the problem?
Thank you and waiting for your kind reply :-)
from aspnetcore.
Hopefully this helps:
I have a master page which loads a partial, it also has some filters:
<form method="get" asp-controller="Review" asp-action="GetReviews" data-ajax="true" data-ajax-update="#filter" data-ajax-mode="replace">
@{
var reviewCount = ReviewController.GetReviewsTotalToList();
ViewBag.ReviewCount = reviewCount;
}
<table class="striped bordered">
<tr>
<th>Reviews per page:</th>
</tr>
<tr>
<td><select name="perPage" onchange="$(this.form).submit();" asp-items="@ViewBag.ReviewCount" id="perPage" class="dropdown-button btn" data-ajax="true" style="max-width:10rem"></select></td>
</tr>
</table>
</form>
<div class="reviewView" id="filter" style="margin-bottom:5rem">
@await Html.PartialAsync("ShowReviewDetails", Model)
</div>
That partial has a paged list, this is the code for the pager:
` Page @(Model.TotalPage < Model.PageIndex ? 1 : Model.PageIndex) of @Model.TotalPage
<form method="get" data-ajax="true" ajax-mode="replace" ajax-update="#filter" >
<pager id="pager1"
class="pagination"
setting-link-attr-data-ajax-update="#filter"
setting-link-attr-data-ajax-mode="replace"
setting-link-attr-data-ajax="true" />`
When the pager first loads, it doesn't use the routes I need, and doesn't seem to use ajax, even if I use setting-link-attr-asp-controller="" or setting-link-attr-route-GetReview="" but if I use a jquery function to update #filter after page load, all of the url info is placed for me
var addy = window.location.protocol + "//" + window.location.host + "/";
var perPage = $("#perPage").val();
$("#filter").load(addy + '/Review/GetReviews?perPage=' + perPage);
I now face new problems as I am trying to make an SPA using ViewComponents, and using the pager loads http://url/?page=2 which seems to break things. I can upload the first project in a zip if you like, but I am learning so it might be a mess :)
from aspnetcore.
@CybrZr00 Thank your for your detailed explaination and sorry for delayed reply. Actually, the pager will use the current URL as the base address when generate the pager link. This works for most scenes, however, if you use SPA, frame or other techinques which rendering nested HTML, the base routing address captured by the tag helper may not be the value you actual wanted, this problem is caused by MVC and HTML design. As a workaround, you may manually set the link URL generator, the following code shows an example:
<pager item-default-link='PagerItemLinkGenerators.Custom((int page) => Url.Action("Index", "Home", new { page = page }))' />
In the above code, the pager will generate the link address /Home/Index?page=1
for the first page.
Hope it helps :-)
from aspnetcore.
I'm closing this issue since the author has no response for days. Pelease feel free to reopen it or submit new issues if you have any further problem.
from aspnetcore.
Related Issues (20)
- When in production, pager fails HOT 3
- An item with the same key has already been added. Key: Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata HOT 13
- Pager is appending extra links after click HOT 3
- VS2017, .NetCore.App 1.1.1 and Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata error HOT 4
- asp-text-source tag helper does not use aspnetcore data annotation localization HOT 4
- Simple pager usage issue HOT 2
- [Documentation] Localization needed for taghelpers HOT 2
- Paging custom parameters HOT 4
- Custom paging parameters cannot be obtained HOT 1
- FlagsEnumModelBinderProvider does not work in .NET Core 2.1 HOT 1
- 【Document】The document is not up to date HOT 4
- The TagHelperde problem was not resolved HOT 2
- Tag helpers seem to be broken on asp.net core 3 HOT 8
- Where is the "source" attribute in "pager" tag? ASP.NET Core 3.0 HOT 1
- Null source in version 3.0.1 HOT 3
- TotalPage Maybe 0 HOT 1
- DataAnnotationsLocalization cannot localize Enums HOT 1
- Can I generate a custom url for setting-link-attr-data-ajax-url? HOT 2
- Enums that don't inherit from int throw errors when attempting to bind HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aspnetcore.