Passing object from jquery ajax to WebAPI results to null

Error processing SSI file

Answers

  1. Elian

    • 2020/7/10

    Instead of trying to receive the posted content as a string, create an object that encapsulates the properties you are posting:

    public class Data
    {
        public int id { get; set; }
        public string name { get; set; }
    }
    

    and then change your controller to:

    public class TestController : ApiController
    {
        public void Post(Data value)
        {
          int id = value.id;
          string name = value.name;
        }
    }
    

    If you really want to receive the posted data as a string this blog post by Darrel Miller might help:

    Posting raw JSON to Web API.

  2. Silvestri

    • 2020/6/6

    Instead of trying to receive the posted content as a string, create an object that encapsulates the properties you are posting: public class Data { public 

  3. Porter

    • 2019/6/19

    Passing object from jquery ajax to WebAPI results to null The value of the variable "value" on the controller is null, although, I pass data to ajax call

  4. Victor

    • 2018/9/9

    I am sending data to a c# web api controller by using the following call. $.ajax({ type: "POST", url: "menuApi/menu/Cost", data: JSON.stringify(order), 

  5. Ryland

    • 2019/6/16

    Ajax post from jquery results in null at Controller #6438. 0 aggarwal created 2 years ago Hi i am following this guidance. The object is still coming as null.

  6. Jaime

    • 2015/9/28

    It is hitting the right controller method. Jquery code action: function (data) { var record = { id: data.record.integration.id }; abp.ajax({ 

  7. Clark

    • 2017/5/16

    Welcome to the next part of a tutorial in the WebAPI series. In this post, I am going to explain, how to post and save the user entered data in the database, using Web API service. If you are new to Web API in ASP.NET MVC5, please refer to the posts given below for the basics of WebAPI. Introduction to WebAPI.

  8. Kyler

    • 2019/8/7

    Jquery/Ajax (changeRole.js) dataType: "json" }).done(function (result) { console.log("action taken: " + result); alert($("#b").text()); }) 

  9. Clyde

    • 2021/10/4

    Use the JSON.stringify() to get the string in JSON format, ensure that while making the AJAX call you pass below mentioned attributes: contentType: ‘application/json’ dataType: ‘json’ Below is the give jquery code to make ajax post call to asp.net web api:

  10. Taylor

    • 2020/6/11

    As a result, the file received in the background is empty. Reason: jQuery's quirk. solve: copy code .ajax({ url: 

  11. Tadeo

    • 2015/9/2

    I have a Web API service call that updates a user's preferences. Unfortunately when I call this POST method from a jQuery ajax call, the request parameter object's properties are always null (or default values), rather than what is passed in. If I call the same exact method using a REST client (I use Postman), it works beautifully.

  12. Aron

    • 2018/7/20

    The value of the TextBox is passed as parameter and the returned response is displayed using JavaScript Alert Message Box. @{. Layout = null;. } < 

  13. Maddox

    • 2021/5/26

    In this article I will explain with an example, how to pass (send) Model object in jQuery $.ajax () POST request to Controller method in ASP.Net MVC 5 Razor. The Controller action method will be called using jQuery AJAX $.ajax () POST request and the Model class object will be passed as JSON object from View in ASP.Net MVC 5 Razor.

  14. Thaddeus

    • 2016/3/4

    It is also passed the text status of the response. As of jQuery 1.5, the success callback function is also passed a "jqXHR" object (in jQuery 1.4, 

  15. Justin

    • 2021/5/8

    How to pass complex object to ASP.NET WebApi GET from jQuery ajax call? (2) I have the following complex object in JavaScript which contains filter options. var filter={caseIdentifiter:'GFT1',userID:'2'}; which I want to pass to an ASP.NET MVC4 WebApi controller GET

  16. Daxton

    • 2016/4/26

    In the success part of the Ajax call, pass this object to a function called productAddSuccess . Add the newly created product data to the HTML 

  17. Martino

    • 2017/12/12

    ajax() will execute the returned JavaScript, calling the JSONP callback function, before passing the JSON object contained in the response to the $. Submit HTML 

Comments are closed.

More Posts