Nancy Model Binding

Hi, I'm studying, Nancy, and I'm trying to get attached to the model, but I get an error message:

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 

Model:

 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<>() }; } } _ => "Hello World"; 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<>() }; } } ); 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<>() }; } } {model}"] = parameters => 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<>() }; } } 

Any tips?

Thank you in advance

+6
source share
1 answer

Methods of binding Nancy model are defined as extension methods in the class NancyModule .

And these extension methods can be found in the namespace Nancy.ModelBinding .

So, you need using namespace Nancy.ModelBinding access to methods Bind() and BindTo() .

So add this line to the source file:

 using Nancy.ModelBinding; 
+17
source

All Articles