处理我的路由问题我在路由中添加了额外的段,而不是将我重定向到编辑操作。
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" }
);
我为PageWithId测试了2个不同的路由集但没有工作
@Html.RouteLink("Edit", "PageWithId",
new
{
controller = "Customers",
action = "Edit",
id = item.CustomerID,
page = ViewBag.CurrentPage
})
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);
}
现在告诉为什么这个网址http://localhost:2020/Customers/Action/Edit/1/AlFAKI
没有重定向我进行编辑操作?
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 }
);
答案 0 :(得分:0)
你的路线看起来不对,我相信你要做的是:
routes.MapRoute(
name: "PageWithId",
url: "{controller}/{action}/{page}/{id}",
defaults: new { controller = "Customers", action = "Edit" }
);