我一直在为 VS 2010 中的一个新的 ASP.NET MVC 4 项目而苦苦挣扎。我有一个非常基本的设置,只有一个控制器 ( SiteController
)、一个路由 ( {action}
) 和一个视图 ( Views/Site/Default.cshtml
)。出于某种原因,我无法让它显示视图,即使路由根据 RouteDebugger 匹配,我得到的只是 404 错误。我以为是 Cassini 是个混蛋,所以我安装了 IIS 7,但它仍然无法正常工作。以下是相关代码:
站点控制器
/// 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