I have same @Html.ActionLink in two parts of .net core mvc application but why they are rendering differently?
Startup :
endpoints.MapControllerRoute(
name: "products",
pattern: "product-category/{title}",
defaults: new { controller = "ProductCategories", action = "ProductsRelatedToCategory", pg = 1 });
Action :
public async Task<IActionResult> ProductsRelatedToCategory(int? cat, int? pg)
{
// using cat to get which category is clicked and pg to get which page it is (in paginated list)
}
in _Layout view:
@Html.ActionLink(
linkText,
"ProductsRelatedToCategory",
"ProductCategories",
null,
null,
null,
new { cat = 14, pg = 1, title = "power-tools" },
new { @class = "menuProductLink" })
Renders right as expected :
"url 1" : {domain}/product-category/power-tools?cat=14
in controller's view (ProductsRelatedToCategory.cshtml) used as next page link in pagination:
@Html.ActionLink(
"Next",
"ProductsRelatedToCategory",
"ProductCategories",
null,
null,
null,
new { cat = productCategory.Id, pg = currentPage + 1, title = "power-tools" },
new { @class = "paginate" })
Renders not right as expected :
"url 2" : {domain}/ProductCategories/ProductsRelatedToCategory?cat=14&pg=2&title=power-tools
Both url's are working fine but actually I want to display url like "url 1", why they are rendered different?