简体   繁体   中英

How to get the post json data in asp.net mvc controller

Can u help me to how to get the json data in controller.

 $.ajax({
    type: 'Post',
    url: 'getdata',
    dataType: 'json',
    data: JSON.stringify(value), //value is an array
    contentType: 'application/json',
    success: function (data) {                    
    },
    error: function (xhr, textStatus, errorThrown) { 
    }
});

Controller:

public ActionResult getdata()
{
   view()
}

I dont have any idea about the controller or model .Suggest some ideas

Jenu,

You'll need to have a parameter of the type that matches your json model along the lines of:

your model may look like:

public class MyModel{
    public string FirstName {get; set;}
    public string LastName{get; set;)
    public bool IsHappy {get; set;}
    // etc. etc
}

public ActionResult GetData(MyModel data)
{
   // do what you need with the data here
   return View();
}

This question is so braod that I think you'd be best to google up some searches for 'json model asp.net mvc' and take it from there. I'll add a few links later.

[edit] - as promised, a few links:

THe final link in the list above almost gives a perfect blow by blow account of what you need to do. I suggest you study that well. good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM