c# - ASP.NET MVC 4 路由匹配,但 Controller 从未被调用

标签 c# asp.net asp.net-mvc asp.net-mvc-4

我一直在 VS 2010 中努力处理一个新的 ASP.NET MVC 4 项目。我已经有了一个非常基本的设置,其中包含单个 Controller (SiteController)、单个路由 ({action}) 和单个 View (Views/Site/Default.cshtml)。由于某种原因,即使路由根据 RouteDebugger 匹配,我也无法让它显示 View ,并且我得到的只是 404 错误。我以为是Cassini是个 SCSS ,所以我安装了IIS 7,但它仍然无法工作。相关代码如下:

站点 Controller

/// Note: BaseController is in a different assembly I use to extend MVC and it works fine because I use it in a dozen other projects.
public class SiteController : BaseController {
    public ActionResult Default() {
        return base.View();
    }
}

路由配置

public class RouteConfig {
    public static void RegisterRoutes(
        /// http(s)://{host}/{action}
        routes.MapRoute("6354af93-f979-44a4-ba9b-cc8ab775edf6", "{action}", new {
            action = "Default",
            controller = "Site"
        });

        /// http(s)://{host}/{*any}
        routes.MapRoute("04b41915-4455-4c11-96c2-38e6aedf929f", "{*any}", new {
            action = "Default",
            controller = "Site"
        });
    }
}

这是项目的文件夹结构:

App_Start
    BundlesConfig.cs
    FilterConfig.cs
    NinjectWebCommon.cs
    RouteConfig.cs
Controllers
    SiteController.cs
Models
Views
    Shared
        _Site.cshtml
    Site
        Default.cshtml
    Web.config
Global.asax
packages.config
Web.Config

最佳答案

结果是我的 BaseController 类导致了 404 错误。不知道为什么,还必须检查该项目,但现在我已将 SiteController 恢复为默认从 Controller 继承。

更新

我花了最后几个小时重建了一个 .NET 扩展解决方案,其中包含我上面引用的 BaseController。我将其重新定位为使用 v4 程序集,并且能够将其重新插入。因此,我想我的错误在于使用了引用 v3 程序集的扩展。

关于c# - ASP.NET MVC 4 路由匹配,但 Controller 从未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19084128/

相关文章:

c# - 如果 Controller 与 View 强绑定(bind),为什么 Controller 需要模型参数?

c# - 如何获取 "left-most 128 bits of a byte array"?

c# - OutputCache VaryByContentEncodings gzip 不起作用

asp.net-mvc - 如何在ckeditor5中上传图像并以base64格式嵌入?

C# ASP.NET MVC3 优于 Ruby on Rails 3、Django?

C# - 从文件中读取特定字符串的字节

c# - Linq to SQL 数据库上下文管理

c# - 使用Session变量来防止未经授权的访问是否安全

javascript - 将带有街景的谷歌地图添加到网页

asp.net-mvc - 将转换应用到 web.config 失败