My routing code is not working.
i am showing data in tabular format with sorting and pagination. my solution is working. when i hover mouse on column then url looks like http://localhost:55831/Customers?page=2&SortColumn=CompanyName&CurrentSort=ContactName
when i click on pagination numeric link then url looks like http://localhost:55831/Customers?page=3&SortColumn=ContactName
i want my url should look like 1) http://localhost:55831/Customers/2/CompanyName/ContactName 2) http://localhost:55831/Customers/3/ContactName
so i add one routing code. here it is
routes.MapRoute(
name: null,
url: "Customers/{page}/{SortColumn}/{CurrentSort}",
defaults: new
{
action = "Index",
page = UrlParameter.Optional,
SortColumn = UrlParameter.Optional,
CurrentSort = UrlParameter.Optional
}
);
after adding the above routing code url looks bit weird. now url looks like
http://localhost:55831/Customers/1/CompanyName/CompanyName?controller=Customers
http://localhost:55831/Customers/2/CompanyName?controller=Customers
so when i click on above links then i am not redirecting to proper controller and action rather getting error.
so it means there is some problem in code which i added as routing in route.config.cs file.
so please help me to get my desired url what i mention above. thanks
EDIT
my full routing code
routes.MapRoute(
name: null,
url: "{controller}/{action}/{page}/{SortColumn}/{CurrentSort}",
defaults: new
{
action = "Index",
page = UrlParameter.Optional,
SortColumn = UrlParameter.Optional,
CurrentSort = UrlParameter.Optional
}
);
routes.MapRoute(
name: null,
url: "{controller}/{action}/{page}/{id}",
defaults: new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
page = UrlParameter.Optional,
}
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);