1

我的路线配置中有以下地图路线。这是第一条路线。

routes.MapRoute(
                "HomePage",
                "",
                new { area = "Accessibility", controller = "Cardholders", action = "Index" }
                );

但是,当我在浏览器中查看我的网站时,我得到

The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Cardholders/Index.aspx
~/Views/Cardholders/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Cardholders/Index.cshtml
~/Views/Cardholders/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml

当我直接浏览我的操作时我没有问题http://localhost:54358/accessibility/cardholders/index

我想要实现的是输入http://localhost:54358并重定向到http://localhost:54358/accessibility/cardholders/index

根据下面的答案,我已经尝试过

routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new {controller = "Cardholders", action = "Index", id = UrlParameter.Optional},
                // Parameter defaults
                new[] { "Plan.Web.Mvc.Areas.Accessibility.Controllers" }
                );

routes.MapRoute(
                "HomePage",
                "Accessibility_Default",
               "Accessibility/{controller}/{id}",
        new { action = "Index", id = UrlParameter.Optional }
                );

routes.MapRoute(
                "HomePage",
                "Accessibility_Default",
               "Accessibility/{controller}/{id}",
        new { action = "Index", id = UrlParameter.Optional }
            );

一切似乎都不起作用。

4

4 回答 4

1

我会尝试回答我自己的问题。

这是一种解决方法,我希望这会有所帮助。

我创建了一个名为“Home”的新区域,并在该区域内创建了一个名为“HomeController”的控制器。

在“家”的区域注册中,我有这个

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute("", "", defaults: new { controller = "Home", action = "Index", area = "Home" });

    context.MapRoute(
        "Home_default",
        "Home/{controller}/{action}/{id}",
        new { action = "Index", id = UrlParameter.Optional }
    );
}

在我的 HomeController 中,我有这个

    public ActionResult Index()
    {
        return RedirectToAction("Index", "Cardholders", new { area = "Accessibility" });
    }
于 2013-08-28T02:30:14.630 回答
0

尝试这样的事情

routes.MapRoute(
                "HomePage",
                "Accessibility_Default",
               "Accessibility/{controller}/{id}",
        new { action = "Index", id = UrlParameter.Optional }
                );

希望这会帮助你。

欲了解更多信息,请点击此处此处

于 2013-08-27T11:40:36.123 回答
0

尝试这个

            routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "controller Name", action = "action name", id = UrlParameter.Optional }, // Parameter defaults
            new[] { "Your Area Controller Namespace" }
        );
于 2013-08-27T12:04:59.877 回答
0

试一试,您只需要替换MyApp为您的项目名称。

例子

routes.MapRoute(
    "HomePage",
    "",
    new { action = "Index" },
    new { controller = "Cardholders" },
    new[] { "MyApp.Areas.Accessibility.Controllers" }
);

当您进行测试时,它会将路线放在顶部,这样您就知道没有其他路线会干扰结果。

于 2013-08-27T12:49:28.337 回答