【问题标题】:Nancy Model Binding南希模型绑定
【发布时间】:2014-03-17 04:44:02
【问题描述】:

您好,我正在学习 Nancy,我正在尝试绑定到模型,但出现错误:

Error   8   'NancyFxTutorial.CarModule' does not contain a definition for 'Bind' and no extension method 'Bind' accepting a first argument of type 'NancyFxTutorial.CarModule' could be found (are you missing a using directive or an assembly reference?) C:\Development\Projects\C#\Web\Nancy\NancyFxTutorial\NancyFxTutorial\CarModule.cs

型号:

public class BrowseCarQuery
{
    public string Make { get; set; }
    public string Model { get; set; }
}

public class CarModule : NancyModule
{
    public CarModule()
    {
        Get["/status"] = _ => "Hello World";

        Get["/Car/{id}"] = parameters =>
            {
                int id = parameters.id;
                return Negotiate.WithStatusCode(HttpStatusCode.OK).WithModel(id);
            };

        Get["/{make}/{model}"] = parameters =>
        {
            BrowseCarQuery model = new BrowseCarQuery();

            var carQuery = this.Bind<>()

        };
    }
}

有什么线索吗?

提前致谢

【问题讨论】:

  • 您是否为正确的命名空间 Nancy.ModelBinding 添加了 using?那么你的文件中有using Nancy.ModelBinding; 吗?

标签: c# model-binding nancy


【解决方案1】:

Nancy model binding 方法在 NancyModule 类上定义为 extension methods

这些扩展方法可以在Nancy.ModelBinding命名空间中找到。

所以你需要usingNancy.ModelBinding命名空间来访问Bind()BindTo()方法。

所以将这一行添加到您的源文件中:

using Nancy.ModelBinding;

【讨论】:

    猜你喜欢
    • 2011-11-13
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 2013-03-30
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多