0

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

apacay
  • 1,702
  • 5
  • 19
  • 41
  • Can you post the code of `Foo` controller? – Tasos K. Aug 06 '16 at 18:00
  • Will do, give me 5' – apacay Aug 06 '16 at 18:01
  • Based on this code, you are not passing a model to your view. That should give an error. If is thats the case with your code, try and remove the line `@model MyModel` to see what will happen. – Tasos K. Aug 06 '16 at 18:16
  • The Model error would be something else, right? not a 404. – apacay Aug 06 '16 at 20:01
  • That's right. That will happen only after the view is successfully located. Also, I'm unable to reproduce the problem locally, following the steps you've provided. – John H Aug 06 '16 at 20:02
  • I should also mention there is no need to alter `Global.asax` for what you're trying to do here. The default route configuration will handle this just fine. – John H Aug 06 '16 at 20:06
  • I even tried creating an Index view to the Foo controller, it's like nothing but the default (hardcoded as default created by scaffolded creation) is considered for the routing. With its ActionResult on FooControlller. – apacay Aug 06 '16 at 20:06
  • Hmm, `I went to the Global.asax and tried placing on Application_Start`, makes it sound as though `Application_Start` doesn't contain anything. It should have 4 calls in there: one for area registration, one for filters, one for routes and a final one for bundles. Does it have all of those? – John H Aug 06 '16 at 20:09
  • 1
    There's definitely something wrong if you're having to generate those yourself. The default MVC application should generate all of that for you. I've zipped up a working solution for you. All I can suggest is taking a look at it to find the differences. You can find it here: https://www.dropbox.com/s/d4t1rfuu5o0dq56/SO-38807208.zip?dl=0 – John H Aug 06 '16 at 20:28
  • Thanks so much for the effort! I'll check that right away – apacay Aug 06 '16 at 21:30

1 Answers1

1

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!)

apacay
  • 1,702
  • 5
  • 19
  • 41