[英]MVC 5 - VS Community 2015 - Routing not working?
It has to be something simple that I'm missing, since this is my first try on MVC. 我必须缺少它,因为这是我第一次尝试MVC。 Seems nothing works but the default route. 似乎没有任何工作,但默认路由。
This were my steps: 这是我的步骤:
localhost:50212 本地主机:50212
to 至
localhost:50212/Foo/Details 本地主机:50212 / Foo /详细信息
Result: I get a 404 结果: 我得到404
Is it that the MVC AreaRegistration
does not happen automatically on compile time? 是不是MVC AreaRegistration
不会在编译时自动发生?
I went to the Global.asax and tried placing on Application_Start 我去了Global.asax并尝试放在Application_Start上
AreaRegistration.RegisterAllAreas();
But that seemed useless. 但这似乎没用。 Any Ideas? 有任何想法吗? Is it that VS community 2015 is missing something? VS Community 2015是否缺少某些内容? Regards 问候
Controllers/FooController.cs 控制器/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();
}
}
}
Views/Foo/Details.cshtml Views / Foo / Details.cshtml
@model MyModel
Hello
App_start of the Global.asax Global.asax的App_start
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, added FooController and Views/Foo/Details @Edit,添加了FooController和Views / Foo / Details
@@Edit: added missing s to Detail s . @@编辑:添加缺少s到详细秒 。 Same error. 同样的错误。
@@@Edit: sharing the Global.asax @@@ Edit:共享Global.asax
I started by working with an MVC 5 template, downloaded from the browsing templates online option on the Add --> New Project Window. 我首先使用MVC 5模板,该模板是从“添加->新建项目”窗口上的“浏览模板在线”选项下载的。
That did not load the things @john-h had on his project. 那并没有加载@ john-h在他的项目中拥有的东西。 It seems that wasn't enough, and I needed to download the MVC nuget package on the project. 似乎还不够,我需要在该项目上下载MVC nuget软件包。 Or simply create a webApp with the mvc option instead of the template. 或者,只需使用mvc选项而不是模板创建一个webApp。
Now its working. 现在可以正常工作了。
(But your solution helped me to figure this out @john-h. Thanks!) (但是您的解决方案帮助我弄清楚了@ john-h。谢谢!)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.