我有两个名为专家和医生的模块。 我创建了一个名为ExpertsController.cs的控制器来处理这两个模块。 它适用于专家,但不适用于医生。 我需要路由路径重定向,将所有路由映射到Experts Controller。 我想对两者使用相同的观点。
等。 www.website.com/Doctors将映射到/专家,客户将不会意识到这一点。
像www.website.com/Docotrs/Edit/1将映射到/ Experts / Edit / 1,客户端将不会意识到这一点。和浏览器将在地址栏中显示www.website.com/Docotrs/Edit/1目前我正在使用此代码:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "ExpertsRoute",
url: "Experts/{action}/{id}",
defaults: new { controller = "Experts", action = "Index", id = UrlParameter.Optional, Doctor = false }
);
routes.MapRoute(
name: "DoctorsRoute",
url: "Doctors/{action}/{id}",
defaults: new { controller = "Experts", action = "Index", id = UrlParameter.Optional, Doctor = true }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
答案 0 :(得分:0)
听起来像ActionLink
正在拿起第一条路线,控制器=“专家”,动作=“索引”,恰好是ExpertsRoute
。请尝试使用RouteLink
来指定您要使用的路线的名称。
示例强>
@Html.RouteLink("Bacon", "DoctorsRoute", new { action = "Edit", id = item.id})