asp.net web api - How to post a string to web API controller? -
i new web api. using visual studio community 2015. simple testing code.
webapiconfig.cs:
config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}" );
view:
$.ajax({ url: 'api/classingalgorithm/', type: 'post', data: { userweightings: json.stringify('hello') } });
controller:
public class classingalgorithmcontroller : apicontroller { [httppost] public classingresult postweightings([frombody]string userweightings) { return null; } }
in controller method, "userweightings" null. why?
change ajax request below.
$.ajax({ url: 'api/classingalgorithm/', type: 'post', contenttype: "application/json", data: json.stringify('hello') });
Comments
Post a Comment