首页 新闻 会员 周边

如何将MVC AREA中的某一个页设为起始页

1
悬赏园豆:10 [待解决问题]

Area中AdminAreaRegistration如下:

 1     public class AdminAreaRegistration : AreaRegistration
 2     {
 3         public override string AreaName
 4         {
 5             get
 6             {
 7                 return "Admin";
 8             }
 9         }
10 
11         public override void RegisterArea(AreaRegistrationContext context)
12         {
13             context.MapRoute(
14                 "Admin_default",
15                 "Admin/{controller}/{action}/{id}",
16                 new { controller="Manage", action = "Index", id = UrlParameter.Optional }
17             );
18         }
19     }

Global.asax中如下设置:

 1         public static void RegisterRoutes(RouteCollection routes)
 2         {
 3             routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
 4 
 5             routes.MapRoute(
 6                 "Default", // 路由名称
 7                 "{controller}/{action}/{id}", // 带有参数的 URL
 8                 new { controller = "Manage", action = "Index", id = UrlParameter.Optional } // 参数默认值
 9             );
10 
11         }
12 
13         protected void Application_Start()
14         {
15             AreaRegistration.RegisterAllAreas();
16 
17             RegisterGlobalFilters(GlobalFilters.Filters);
18             RegisterRoutes(RouteTable.Routes);
19         }

运行时提示

未找到视图“Index”或其母版视图,或没有视图引擎支持搜索的位置。搜索了以下位置:
~/Views/Manage/Index.aspx
~/Views/Manage/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Manage/Index.cshtml
~/Views/Manage/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml

TannySiu的主页 TannySiu | 初学一级 | 园豆:76
提问于:2013-01-15 15:08
< >
分享
所有回答(4)
0

两个 路由 都把 命名空间带上, context.MapRoute(
                 "Admin_default",
                 "Admin/{controller}/{action}/{id}",
                 new { controller="Manage", action = "Index", id = UrlParameter.Optional },
                  new string[] { "控制器的命名空间" }
             );

Global.asax 中的 也加上。

Qlin | 园豆:2403 (老鸟四级) | 2013-01-15 15:15

我在路由中加上命名空间,如下所示

1         public override void RegisterArea(AreaRegistrationContext context)
2         {
3             context.MapRoute(
4                 "Admin_default",
5                 "Admin/{controller}/{action}/{id}",
6                 new { controller="Manage", action = "Index", id = UrlParameter.Optional },
7                 new string[] { "MvcApplication15.Areas.Admin.Controllers" }
8             );
9         }

还是出现同样的错误

支持(0) 反对(0) TannySiu | 园豆:76 (初学一级) | 2013-01-15 15:43

@TannySiu: 

检查一下你的地址,或者真的有问题, 贴出来看看

支持(0) 反对(0) Qlin | 园豆:2403 (老鸟四级) | 2013-01-15 15:50

@Qlin: 需要我贴什么资料?我现在做测试,就新建了一个MVC3的程序,然后添加Area,增加了一个控制器ManageController和一个视图Index,然后就修改AdminAreaRegistration和Global.asax,想测试一下Area中的ManageController中的Index视图做为起始页,很简单的一个测试

支持(0) 反对(0) TannySiu | 园豆:76 (初学一级) | 2013-01-15 16:04

@TannySiu: 

贴地址 ,浏览器中的地址

支持(0) 反对(0) Qlin | 园豆:2403 (老鸟四级) | 2013-01-15 16:16

@Qlin: 地址怎么贴法

支持(0) 反对(0) TannySiu | 园豆:76 (初学一级) | 2013-01-15 16:22

@TannySiu: 

好吧,浏览器中的地址,请求的地址

支持(0) 反对(0) Qlin | 园豆:2403 (老鸟四级) | 2013-01-15 16:25

@Qlin: 请求地址没有问题

默认是 http://localhost:5810/ 这个提示错误

输入http://localhost:5810/admin 时可以正常显示

支持(0) 反对(0) TannySiu | 园豆:76 (初学一级) | 2013-01-15 16:29

@TannySiu: 

routes.MapRoute(
               "Default", // 路由名称
                 "{controller}/{action}/{id}", // 带有参数的 URL
                 new { controller = "Manage", action = "Index", id = UrlParameter.Optional } // 参数默认值
            );

这个 加了命名空间没?
支持(0) 反对(0) Qlin | 园豆:2403 (老鸟四级) | 2013-01-15 16:38

@Qlin: 

Global.asax中也加了

 1         public static void RegisterRoutes(RouteCollection routes)
 2         {
 3             routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
 4 
 5             routes.MapRoute(
 6                 "Default", // 路由名称
 7                 "{controller}/{action}/{id}", // 带有参数的 URL
 8                 new { controller = "manage", action = "Index", id = UrlParameter.Optional }, // 参数默认值
 9                 new string[] { "MvcApplication15.Areas.Admin.Controllers" }
10             );
11 
12         }
支持(0) 反对(0) TannySiu | 园豆:76 (初学一级) | 2013-01-15 16:41

@TannySiu: 

那 views   中 有没有这个页面

支持(0) 反对(0) Qlin | 园豆:2403 (老鸟四级) | 2013-01-15 17:07

@Qlin: Area下有View还是最外层的View,Area下的肯定有的

支持(0) 反对(0) TannySiu | 园豆:76 (初学一级) | 2013-01-15 17:11

@TannySiu: 

好吧 ,它访问哪个view,就检查哪个,我要 吐血了 

支持(0) 反对(0) Qlin | 园豆:2403 (老鸟四级) | 2013-01-15 17:15

这个是目录图,ManageController下的Index也是有的,浏览器中直接输入地址也可以访问,就是无法做为运行时的起始页

支持(0) 反对(0) TannySiu | 园豆:76 (初学一级) | 2013-01-15 17:34

@TannySiu:呃,我觉的是这样,你的

routes.MapRoute(
                "areasDefault", // 路由
                  "", //这里要空白
                  new { controller = "manage", action = "Index", id = UrlParameter.Optional }, // 参数默认值
                 new string[] { "MvcApplication15.Areas.Admin.Controllers" }
            );
支持(0) 反对(0) 键盘上的考拉 | 园豆:207 (菜鸟二级) | 2013-05-15 16:43
0

MVC那个项目属性→Web→特定页→Admin,这样就可以了

aehyok | 园豆:1212 (小虾三级) | 2013-03-09 12:22
0
routes.MapRoute(
                "areasDefault", // 路由
                  "", //这里要空白
                  new { controller = "manage", action = "Index", id = UrlParameter.Optional }, // 参数默认值
                 new string[] { "MvcApplication15.Areas.Admin.Controllers" }
            );
键盘上的考拉 | 园豆:207 (菜鸟二级) | 2013-05-15 17:26
4

public static void RegisterRoutes(RouteCollection routes)
{
  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

  routes.MapRoute(
      name: "Default",
      url: "{controller}/{action}/{id}",
      defaults: new { controller = "Home", action = "Login", id = UrlParameter.Optional},
      namespaces:new string[]{"MVCUI.Areas.自己Area的名称.Controllers"}
      ).DataTokens.Add("Area","自己Area的名称");
}

xsauce | 园豆:110 (初学一级) | 2013-07-24 10:57

牛逼  佩服

支持(0) 反对(0) xiaojiange | 园豆:200 (初学一级) | 2014-08-13 19:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册