【问题标题】:Nancy: Basic module not triggeringNancy:基本模块未触发
【发布时间】:2015-06-01 15:18:22
【问题描述】:

我想我误解了一些东西。我来自 MVC 世界,并被告知 Nancy 模块是 MVC 中的控制器的同义词。

当你第一次创建一个新项目时,你会得到一个这样的基本模块:

public class IndexModule : NancyModule {
    public IndexModule(){
        Get["/"] = parameters => View["index", new ViewModels.IndexModel()];
    }
}

效果很好。但后来我想创建一个新模块,我继续创建这个:

class HomeModule:NancyModule {
    public HomeModule():base("/home"){ // i saw the "base()" trick in samples
        Get["/"] = p => View["home"];
    }
}

但是这不起作用。当我访问http://localhost:3579/home 时得到 404,并且模块根本没有被触发。那么这是如何工作的,我什至应该像这样构造它吗?

【问题讨论】:

    标签: nancy


    【解决方案1】:

    好吧,没关系,我刚刚解决了它。我只需要将 HomeModule 类公开。

    public class HomeModule:NancyModule {
        public HomeModule():base("/home"){
            Get["/"] = p => View["home"];
        }
    }
    

    【讨论】:

    • 我在重构一个项目时遇到了这个问题。您扩展的 NancyModule 似乎需要是一个公共类。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    • 1970-01-01
    相关资源
    最近更新 更多