尝试这个:
routes.MapRoute(
name: "van-insurance/quote1",
url: "van-insurance/quote1",
defaults: new { controller = "EditVehicleController", action = "Show", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "van-insurance/quote2",
url: "van-insurance/quote2",
defaults: new { controller = "EditProposerController", action = "Show", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "van-insurance/quote3",
url: "van-insurance/quote3",
defaults: new { controller = "EditAdditionalDriversController", action = "Show", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "van-insurance/quote4",
url: "van-insurance/quote4",
defaults: new { controller = "EditPolicyController", action = "Show", id = UrlParameter.Optional }
);
无论如何,我建议您使用另一种方法,因为这种方法不容易改变。
var vanInsuranceRoutes = new List<Tuple<string, string>>
{
new Tuple<string, string>("quote1", "EditVehicleController"),
new Tuple<string, string>("quote2", "EditProposerController"),
new Tuple<string, string>("quote3", "EditAdditionalDriversController"),
new Tuple<string, string>("quote4", "EditPolicyController"),
};
foreach (var route in vanInsuranceRoutes)
{
routes.MapRoute(
name: string.Format("van-insurance/{0}", route.Item1),
url: string.Format("van-insurance/{0}", route.Item1),
defaults: new { controller = route.Item2, action = "Show", id = UrlParameter.Optional });
}
你可以提高代码的质量,但你明白了。