knockout.js - ASP.Net WebAPI ActionName Route Not Found -
i trying create webapi controller multiple commands using actionname method. did on project, have been having problems latest project , cannot see understand why knockout view model ajax call cannot find specific uri.
webapiconfig.cs:
config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{action}/{id}", defaults: new { id = routeparameter.optional } );
controller:
// api/lot [actionname("default")] public ienumerable<dataobject> get() { //... } // api/lot/specific/5 [actionname("specific")] public ienumerable<dataobject> get(int? data) { //... } // api/lot/5 public string get(int id) { return "value"; }
my default action works perfect specific action continues have error when attempt call view-model:
"failed load resource: server responded status of 404 (not found)"
i added [httpget] next [actionname("specific")] , had following error:
"get http://localhost:57492/api/lot/specific/1 404 (not found)"
i've tried several different things such removing int? data argument, when attempt build project tells me existing function same arguments exists, different action names.
ultimately have multiple get(parameter) actions call interacting view-model.
i able solve adding route property httpget , renaming of functions unique names getall(), getspecific(ind id), etc..
// api/lot [httpget] [route("api/lot/getall")] public ienumerable<dataobject> getall() {...} // api/lot/getspecific/{id} [httpget] [route("api/lot/getspecific/{id}")] public ienumerable<dataobject> getspecific(string id) {
Comments
Post a Comment