to handle my routing issue i add extra segment in routing which not redirecting me to edit action.
see my routing which causing problem
- routes.MapRoute
- (
- name: "PageWithId",
- url: "Customers/Action/Edit/{page}/{id}",
- defaults: new { controller = "Customers", action = "Edit" }
- );
-
- OR
-
- routes.MapRoute
- (
- name: "PageWithId",
- url: "Customers/Edit/Action/{page}/{id}",
- defaults: new { controller = "Customers", action = "Edit" }
- );
i test above 2 different set of routing for PageWithId but none work
see RouteLink code
- @Html.RouteLink("Edit", "PageWithId",
- new
- {
- controller = "Customers",
- action = "Edit",
- id = item.CustomerID,
- page = ViewBag.CurrentPage
- })
- my edit action code
- public ActionResult Edit(int page, string id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- Customer customer = db.Customers.Find(id);
- if (customer == null)
- {
- return HttpNotFound();
- }
- ViewBag.CurrentPage = page;
- return View(customer);
- }
now tell why this url http://localhost:2020/Customers/Action/Edit/1/AlFAKI not redirecting me to edit action?
see my full routing code
- routes.MapRoute(
- name: "PageWithSort",
- url: "{controller}/{action}/{page}/{SortColumn}/{CurrentSort}",
- defaults: new { action = "Index", page = UrlParameter.Optional, SortColumn = UrlParameter.Optional, CurrentSort = UrlParameter.Optional }
- );
-
-
- routes.MapRoute
- (
- name: "PageWithId",
- url: "Customers/Action/Edit/{page}/{id}",
- defaults: new { controller = "Customers", action = "Edit" }
- );
-
- OR
-
- routes.MapRoute
- (
- name: "PageWithId",
- url: "Customers/Edit/Action/{page}/{id}",
- defaults: new { controller = "Customers", action = "Edit" }
- );
-
- routes.MapRoute(
- name: "Default",
- url: "{controller}/{action}/{id}",
- defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
- );