码迷,mamicode.com
首页 > 编程语言 > 详细

directly receive json data from javascript in mvc

时间:2014-09-10 14:09:40      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   os   io   java   ar   

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]);
            

bubuko.com,布布扣

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

directly receive json data from javascript in mvc

标签:des   style   blog   http   color   os   io   java   ar   

原文地址:http://www.cnblogs.com/langu/p/3964261.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!