if you send json data to mvc,how can you receive them and parse them more simply?

you can do it like this:

            latestData = [];
            $('.save').click(function () {
                $('.content tr').each(function () {                   
                    var item = { id:null,date: '', weekday: '', holiday: ''}; 
latestData.push(item); }); $.post(url , JSON.stringify(latestData) ,
function (data) {}); });

 

if you have a entity which has same properties with the 'item',then you can parse json like this:

 IList<Holidays> holidays = new JavaScriptSerializer().Deserialize<Holidays[]>(ControllerContext.HttpContext.Request.Form[0]);
            

directly receive json data from javascript in mvc

pay attention to red line,don't need any pramaters in action,deserialized type is an array.

相关文章:

  • 2021-07-22
  • 2022-12-23
  • 2021-05-15
  • 2022-12-23
  • 2021-06-08
  • 2021-12-08
  • 2022-12-23
  • 2021-04-19
猜你喜欢
  • 2021-11-18
  • 2021-12-09
  • 2021-11-06
  • 2022-03-09
  • 2022-12-23
  • 2022-03-01
  • 2021-07-08
相关资源
相似解决方案