У меня есть требование, в котором я должен карту по следующей ссылкеДобавление маршрутизации в MVC 5
/amer/us/en/ = Home controller
/amer/us/en/login/index = Home controller
/amer/us/en/confirmation = Confirmation controller
наряду с обычным действием по умолчанию.
Например, если пользователь переходит на
http:\\test.com --> http://test/home/index
http:\\test.com/amer/us/en/login/index --> http://test/home/index
http:\\test.com/amer/us/en/ --> http://test/home/index
Я искал в маршрутизации атрибутов и поэтому я добавил следующий код в HomeController
[RoutePrefix("amer/us/en/")]
[Route("{action=index}")]
public class HomeController : Controller
{
}
, и я получаю эту ошибку The route prefix 'amer/us/en/' on the controller named 'Home' cannot begin or end with a forward slash
, а также по умолчанию маршрутизация сейчас не работает, поэтому http://test.com ничего не загружает. Ниже приведен мой класс RouteConfig по умолчанию.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Очень новый для MVC. Может кто-нибудь сказать мне, что я делаю неправильно здесь.
Отлично работает .. Спасибо. – user1221989