asp.net-mvcasp.net-mvc-5vs-community-editionmvcroutehandler

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. Seems nothing works but the default route.

This were my steps:

  1. Create new solution from an MVC5 template (Which comes with a HomeController and a Controller/Action/Id by default on the RouterConfig.Configuration.
  2. Add --> Controller named Foo --> Create an ActionResult named Details
  3. Add a View named Details
  4. Run the MVC project
  5. Appears the home page, and I change the url from

localhost:50212

to

localhost:50212/Foo/Details

Result: I get a 404

Is it that the MVC AreaRegistration does not happen automatically on compile time?

I went to the Global.asax and tried placing on Application_Start

AreaRegistration.RegisterAllAreas();

But that seemed useless. Any Ideas? Is it that VS community 2015 is missing something? Regards

Controllers/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

@model MyModel

Hello

App_start of the 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, added FooController and Views/Foo/Details

@@Edit: added missing s to Details. Same error.

@@@Edit: sharing the Global.asax


Solution

  • I started by working with an MVC 5 template, downloaded from the browsing templates online option on the Add --> New Project Window.

    That did not load the things @john-h had on his project. It seems that wasn't enough, and I needed to download the MVC nuget package on the project. Or simply create a webApp with the mvc option instead of the template.

    Now its working.

    (But your solution helped me to figure this out @john-h. Thanks!)