Hi I'm learning Nancy and I'm trying to bind to a model, but I'm getting the error:
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<>()
};
}
}
any clues?
Thanks in advance
The Nancy model binding methods are defined as extension methods on the NancyModule
class.
And these extension methods can be found in the Nancy.ModelBinding
namespace.
So you need to using
the Nancy.ModelBinding
namespace to access the Bind()
and BindTo()
methods.
So add this line to your source file:
using Nancy.ModelBinding;