を働いていない私は、生成されたエンティティフレームワークのAPIコントローラを持って、私は今それに新しいメソッドを追加しようとしています:ASP.NET Entity FrameworkのAPIコントローラメソッドを追加
[ResponseType(typeof(LCPreview))]
public IHttpActionResult ValidateEmail(string email)
{
LCPreview lCPreview = db.Data.Find(5);
if (lCPreview == null)
{
return NotFound();
}
return Ok(lCPreview);
}
が、私はこれを実行すると、
規則ベースのルーティングテーブルをルーティングするには二つの動作を区別することができません経由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 }
);
}
db.Data.Findコールから返されたオブジェクトをチェックしましたか?これは、idフィールドにnull値を持つ可能性があります。 –
私はブレークポイントを入れました、その新しいメソッドを打つことは全くありません – user979331
ルート競合。それは要求に合った別のルートを打っています。ルート設定の構成方法を示します。 URLが要求されています – Nkosi