2013-08-27 48 views
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 } 
      ); 

似乎都没有工作。

回答

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" }); 
    } 
0

尝试这样的事情

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

希望这会帮助你。

欲了解更多信息,请遵循herehere

+0

这不起作用 –

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" } 
     ); 
+0

不工作太 –

0

给此一去,你只需要与你的项目的名称,以取代MyApp

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

当你正在测试它把路由顶部,让你知道没有其他途径与结果的干扰。

+0

我已经用Plan.Web.Mvc替换了MyApp,这是我的项目名称,但不起作用 –

相关问题