首页 新闻 赞助 找找看

MVC5分区后分区里面的控制器找不到相应的视图

0
悬赏园豆:50 [已解决问题] 解决于 2019-04-03 23:15

根据RouteConfig配置,可以访问区域里面的控制器并执行相应的动作,但是返回视图时找不到视图,报错信息如下:

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

配置如下路由:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new {controller = "Login", action = "Index", id = UrlParameter.Optional},
            constraints: new {controller = "Login", action = "Index" },
            namespaces: new string[]{ "Crazy.Web.Admin.User.Controllers" }
        );
    }

}

public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
name:"Home_default",//路由名称
url: "Home/{controller}/{action}/{id}",//url
defaults:new { controller= "Index", action = "Index", id = UrlParameter.Optional
}//默认路由
);
}

江小白鞋的主页 江小白鞋 | 初学一级 | 园豆:102
提问于:2019-04-02 20:05

可以通过控制器直接查看视图

江小白鞋 4年前
< >
分享
最佳答案
0

你直接用代码 目录文件操作 尝试一下就知道了。Direcotry和File操作。

收获园豆:50
花飘水流兮 | 专家六级 |园豆:13560 | 2019-04-03 10:44

不好意思,不清楚您的意思

江小白鞋 | 园豆:102 (初学一级) | 2019-04-03 22:59
其他回答(1)
0

把RegisterRouter里面默认生成的路由删除掉,就可以了???????按理说,我的路由写了区域啊,不可能匹配上默认路由的,弄不懂

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

            //routes.MapRoute(
            //    name: "Default",
            //    url: "{controller}/{action}/{id}",
            //    defaults: new {controller = "Login", action = "Index", id = UrlParameter.Optional},
            //    constraints: new {controller = "Login", action = "Index" },
            //    namespaces: new string[]{ "Crazy.Web.Admin.User.Controllers" }
            //);
        }
江小白鞋 | 园豆:102 (初学一级) | 2019-04-03 23:11

原本不注释默认路由是不能进入分区路由的,自己注释默认路由后可以访问了,再不注释,尼玛还是可以访问了,玩我了???编译问题,也不对啊,电脑都换了2个

支持(0) 反对(0) 江小白鞋 | 园豆:102 (初学一级) | 2019-04-03 23:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册