因为这是我第一次尝试MVC,所以它必须是我错过的一些简单的东西。似乎什么都不管用,只有默认的路线。
这是我的脚步:
本地主机:50212
至
本地主机:50212/Foo/详细信息
结果:我得到了一个404
是因为MVC AreaRegistration不会在编译时自动发生吗?
我去了Global.asax,试着在Application_Start上放
AreaRegistration.RegisterAllAreas();但这似乎毫无用处。有什么想法吗?是因为VS 2015社区缺少了什么吗?问候
控制器/FooController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcTest.Controllers
{
public class FooController : Controller
{
// GET: Foo
public ActionResult Details()
{
return View();
}
}
}视图/Foo/Details.cshtml
@model MyModel
HelloApp_start of Global.asax
namespace MvcTest
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
AreaRegistration.RegisterAllAreas();
//This up here is something I added manually after its byDefault scaffolding
FilterConfig.Configure(GlobalFilters.Filters);
RouteConfig.Configure(RouteTable.Routes);
}@Edit,添加了FooController和视图/Foo/详细信息
@@Edit:在Details中添加缺少的s。同样的错误。
@编辑:共享Global.asax
发布于 2016-08-07 02:09:27
我首先使用MVC 5模板,它是从Add -> New窗口的浏览模板在线选项下载的。
这并没有载入@john-h在他的项目中所拥有的东西。这似乎还不够,我需要在项目上下载MVC nuget包。或者使用mvc选项创建一个webApp,而不是模板。
现在起作用了。
(但你的解决方案帮我弄明白了“约翰-h”。谢谢!)
https://stackoverflow.com/questions/38807208
复制相似问题