【问题标题】:FubuMvc: If I move my controller and views into a folder I get a 404FubuMvc:如果我将控制器和视图移动到文件夹中,我会得到 404
【发布时间】:2012-02-15 20:14:52
【问题描述】:

我是 FubuMvc 的新手,我只是在一个小项目上玩弄它。

我有默认的 nuget 包 fubu 配置,并且我正在使用 Web 表单视图引擎:

    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>();
    }

我在站点根目录中创建了一个控制器和一个视图,如下所示: ~/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; }
    }
}
}

以及随之而来的视图: ~/Index.aspx

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

当我浏览到 ~/Index 时,它工作正常。

现在我想将我的控制器移动到一个新文件夹“电影”中。所以我移动了控制器和视图,并将控制器上的命名空间更改为 MoviesApp.Movies。 当我导航到 ~/Movies/Index 时,它在我的 IndexController.Index() ActionMethod 中遇到断点,但随后显示 404。

有什么想法吗?

【问题讨论】:

    标签: fubumvc


    【解决方案1】:

    我假设您使用的是 WebForms 引擎,对吧?对于 WebForms 视图解析,FubuMVC 假设视图的命名空间与视图位置完全匹配。当您移动视图时,这两件事不再匹配。如果您安装了 R#,只需打开后面的代码并让它调整命名空间——并确保命名空间在 aspx 上也得到更改。

    更好的建议可能是切换到 Spark 视图引擎或 FubuMVC 中的 Razor 支持已经在运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-06
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多