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

Popular posts from this blog

mongodb - Struggling to get ordered results from the last retrieved article, given array of elements to search in -

c# - Pausing a storyboard on TabItem mouse over -

c# - Attribute value in root node of xml Linq to XML -