asp.net web api2 - Web Api 2 Post - UrlHelper.Link must not return null -


i have basic web api 2 setup basic routing.

below default route , post inserts. when call post record created in database "createdatroute" call returns 500 error stating:

exceptionmessage: "urlhelper.link must not return null." exceptiontype: "system.invalidoperationexception"

why receive error?

[routeprefix("api/casenotes")]     public class casenotecontroller : apicontroller...    // post api/casenote [route("")] [responsetype(typeof(client_admission_casenote))]     public async task<ihttpactionresult> postclient_admission_casenote   (client_admission_casenote client_admission_casenote) {    request.getrequestcontext().includeerrordetail = true;    if (!modelstate.isvalid)   {       return badrequest(modelstate);   }    db.client_admission_casenote.add(client_admission_casenote);   await db.savechangesasync();    return createdatroute("defaultapi", new { id = client_admission_casenote.casenote_id }, client_admission_casenote);     } 

since using attribute routing.. have name route.. i.e. [route("api/books/{id}", name="getbookbyid")]

and use route name on url.link() call

see details here.. http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2#route-names


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -