Reputation: 53
I want to use url parameter named page in my razor pages app:
http://example.com/Dataset/0?page=X
I tried using anchor tag helper like this:
<a asp-page="Dataset" asp-route-id="@(dataset.Id)" asp-route-page="@(pageNumber)">@(dataset.Title)</a>
But this doesnt work, it seems like asp-page and asp-route-page conflict each other, the result is:
http://example.com/Dataset/0
The above can be easily solved by typing it out in html so its not a real problem there.
The real problem: I tried manually adding ?page=100 to the end of url, i checked the value in the OnGet method and its 0 as if the parameter is missing.
edit: this method gets called when you visit the razor page in browser, the parameters of the method have the same name as parameters from the url query, they get automatically filled from the query, except the page parameter
public FileResult OnGet(int id, string subject, string predicate, string @object, int page)
{
// page==0 in this scope even if the query is ?page=30 etc
// other parameters work fine
}
Upvotes: 0
Views: 3463
Reputation: 109
In this context "Page" is a reserved term, so you should not use it in your route or it will confuse the routing engine.
Marshall
Upvotes: 2
Reputation: 2404
You can't use page as route value for a razor page because that route value is used by the razor pages engine.
The path to raozor page is added to the route diccionary values as a route value with the page key so just change the name of the route value.
Upvotes: 0
Reputation: 36
There are couple of ways to send parameters in Razor syntax. You can use
@Html.ActionLink("Title","0","Dataset",new{page=100})
Or You can use tag like:
<a href="http://example.com/Dataset/0?page=@pageNumber">@dataset.Title</a>
Upvotes: 0