How do you post a JSON file to an ASP.NET MVC Action?

前端 未结 5 1606
予麋鹿
予麋鹿 2020-12-01 18:51

My iphone client posts the following json to my mvc service. When posting data from html form it automatically converts form data to UserModel and passes the object to my Cr

5条回答
  •  时光取名叫无心
    2020-12-01 19:19

    Late but hope it helps someone.

    What would be the cleanest solution to do the conversion from JSON to Object?

    
    
    $.post("http://localhost:52161/Default/PostRawJson/", { json: {
       "firstName" : "Some Name",
       "lastName" : "Some Last Name",
       "age" : "age"
    }});
    
    
    public void PostRawJson(string json)
    {
        var person = System.Web.Helpers.Json.Decode(json);
        person.firstname...
    }
    

    This way you get a pure JSON object to work with in your controller as requested.

提交回复
热议问题