jquery - Web API Controller not found on PUT -
i having trouble finding put action of web api 2 controller. i'm using mvc5. action in controller found , working when called. have tried several different ways of hitting this, no avail. appreciate hints.
the jquery call:
var data = { id: 1, text: 'test' }; var jsondata = json.stringify(data); $.ajax({ url: serviceroot + "approval/" + id, type: 'put', contenttype: "application/json; charset=utf-8", data: jsondata, success: function (results) { alert('content saved.'); } }) the request object used in controller:
public class contentrequest { public int id { get; set; } public string text { get; set; } } route startup:
routes.maproute( name: "default", url: "{controller}/{action}/{id}", defaults: new { controller = "home", action = "index", id = urlparameter.optional } ); the controller:
using system.collections.generic; using system.web.http; using system.net; using system.net.http; namespace seacretgarden.web.controllers { public class approvalcontroller : apicontroller { [httpput] public ihttpactionresult put(int id, contentrequest content) { return statuscode(httpstatuscode.nocontent); } } } edit: resolution problem add following web.config file: ( using mvc5 web api controllers )
<modules> <remove name="formsauthentication" /> <remove name="webdavmodule"/> </modules> <handlers> <remove name="extensionlessurlhandler-integrated-4.0" /> <remove name="optionsverbhandler" /> <remove name="traceverbhandler" /> <remove name="webdav"/> <add name="extensionlessurlhandler-integrated-4.0" path="*." verb="*" type="system.web.handlers.transferrequesthandler" precondition="integratedmode,runtimeversionv4.0" /> </handlers>
the resolution problem add following web.config file: ( using mvc5 web api controllers ):
<modules> <remove name="formsauthentication" /> <remove name="webdavmodule"/> </modules> <handlers> <remove name="extensionlessurlhandler-integrated-4.0" /> <remove name="optionsverbhandler" /> <remove name="traceverbhandler" /> <remove name="webdav"/> <add name="extensionlessurlhandler-integrated-4.0" path="*." verb="*" type="system.web.handlers.transferrequesthandler" precondition="integratedmode,runtimeversionv4.0" /> </handlers>
Comments
Post a Comment