首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在不同的父文件夹中正确地路由mvc控制器?

问如何在不同的父文件夹中正确地路由mvc控制器?
EN

Stack Overflow用户
提问于 2012-01-09 09:00:32
回答 3查看 2.3K关注 0票数 2

我找不到解决这个问题的办法。

我必须在一个项目中加入两个MVC3项目。要做到这一点,我必须把它们放在不同的文件夹中。为了理解我的意思,让我们看看这些图像:

第一个项目:

​

​

放进文件夹后:

​

​

现在,当我运行该项目时,我得到了以下错误:

代码语言:javascript
复制
Server Error in '/' Application.

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

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

在Global.asax内部:

代码语言:javascript
复制
namespace MvcApplication1
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

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

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}  

问题:

  1. 我的global.asax的配置应该是什么?(因为我怀疑问题是从这里开始的)
  2. ,如果第一个问题是可以解决的,那么我将如何绘制第二个MVC3项目的路线?

非常感谢!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-01-09 09:02:48

尝试使用来自Asp.net MVC-3的“区域”。

这样,您就可以最好地控制URL和输出。

票数 4
EN

Stack Overflow用户

发布于 2012-01-09 09:38:05

在MVC3中,区域是非常好的特性,您可以这样简单地进行路由。

代码语言:javascript
复制
"MVCApplication1/{controller}/{action}/{id}"

"MVCApplication2/{controller}/{action}/{id}"

see here

票数 1
EN

Stack Overflow用户

发布于 2016-05-18 23:16:10

在Global.asax中,检查是否已经注册了这些区域。

代码语言:javascript
复制
protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8785898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档