首页 > 解决方案 > 使用 asp.net mvc 重定向路由

问题描述

我是 MVC 的新手,所以请在这里帮助我。我需要重定向myhost.com/contactusmyhost.com/aController/aView.

我试过了

routes.MapRoute(
            name: "contactus",
            url: "contactus",
            defaults: new { controller = "aController", action = "aView"}
        );

但没有运气。我错过了什么:(

标签: asp.net-mvcurl-redirection

解决方案


你可以试试这个:

 routes.MapRoute(
            "contactus",
            "{controller}/{action}/{id}",
            new { controller = "aController", action = "aView", id = UrlParameter.Optional },

        );

推荐阅读