Search code examples
fubumvc

FubuMvc: If I move my controller and views into a folder I get a 404


I'm new to FubuMvc and I'm just playing around with it on a small project.

I have the default nuget package fubu configuration, and I'm using web forms view engine:

    public ConfigureFubuMVC()
    {
        // This line turns on the basic diagnostics and request tracing
        IncludeDiagnostics(true);

        // All public methods from concrete classes ending in "Controller"
        // in this assembly are assumed to be action methods
        Actions.IncludeClassesSuffixedWithController();

        // Policies
        Routes
            .IgnoreControllerNamesEntirely().IgnoreControllerFolderName()
            .IgnoreMethodSuffix("Html")
            .RootAtAssemblyNamespace();

        // Match views to action methods by matching
        // on model type, view name, and namespace
        Views.TryToAttachWithDefaultConventions();

        // View Engine
        this.Import<WebFormsEngine>();
    }

I've created a controller and a view in my site root, like so: ~/IndexController.cs

namespace MovieApp
{
public class IndexController
{
    private MoviesDBEntities _db = new MoviesDBEntities();

    public MovieIndexViewModel Index()
    {
        return new MovieIndexViewModel { Movies = _db.Movies.ToList() };
    }

    public class MovieIndexViewModel
    {
        public IEnumerable<Movie> Movies { get; set; }
    }
}
}

and the View that goes with it: ~/Index.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" MasterPageFile="/Site.Master" Inherits="MovieApp.Index" %>
...

When I browse to ~/Index it works fine.

Now I want to move my controller into a new folder, "Movies". So I move the controller and the view, and I change the namespace on the controller to be MoviesApp.Movies. When I navigate to ~/Movies/Index, it hits a breakpoint in my IndexController.Index() ActionMethod, but then a 404 is displayed.

Any ideas?


Solution

  • I assume that you're using the WebForms engine, right? For WebForms view resolution, FubuMVC makes the assumption that the namespace of the view exactly matches the view location. When you moved the views around those two things no longer match. If you've got R# installed, just open the code behind and have it adjust the Namespace -- and make sure the namespace gets changed on the aspx as well.

    The better advice is probably to switch to the Spark view engine or Razor support in FubuMVC is already in flight.