POST JSON with MVC 4 API Controller

后端 未结 5 1761
刺人心
刺人心 2020-12-09 10:01

I have this code:

   $.ajax({


        type: \"POST\",
        url: \"/api/slide\",
        cache: false,
        contentType: \"application/json; charset=u         


        
5条回答
  •  [愿得一人]
    2020-12-09 10:40

    $.ajax({
        type: 'POST',
        url: '/api/slide',
        cache: false,
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify({ title: "fghfdhgfdgfd" }),
        success: function() {
            ...    
        }
    });
    

    Controller is

    public class SlideController : ApiController
    {
    
        // POST /api/Slide
        public void Post(string Title)
        {
        }
    

    Your url is not valid, url must address the action Post in Slide controller

    edit your url to url:"~/ControllerName/ActionName" in this context must be Url:"~/Slide/Post"

提交回复
热议问题