I have a Entity Framework API Controller that was generated, I am now trying to add a new method to it:
[ResponseType(typeof(LCPreview))]
public IHttpActionResult ValidateEmail(string email)
{
LCPreview lCPreview = db.Data.Find(5);
if (lCPreview == null)
{
return NotFound();
}
return Ok(lCPreview);
}
but when I run this, I get this error:
The request is invalid. The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Http.IHttpActionResult GetLCPreview(Int32)' in 'Astoria.Controllers.PreviewLCAPIController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}