Angular POST to Web API doesn't pass data

后端 未结 3 1606
一个人的身影
一个人的身影 2021-01-18 15:44

I\'ve been writing code against ASP.NET Web API for a while now with jQuery and I\'m starting something new in Angular (writing against the same Web API backend.)

I\

3条回答
  •  孤独总比滥情好
    2021-01-18 16:12

    Check if you have included the JSON Formatter in your configuration. It should be something like :

        System.Web.Http.GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
        config.Formatters.Insert(0, new System.Net.Http.Formatting.JsonMediaTypeFormatter());
    

    The Content-Type=application/json only will work if you set the proper formatter.

    You can also try using [FromBody] next to your parameter type.

提交回复
热议问题