directly receive json data from javascript in mvc

本文介绍了一种使用JavaScript简化JSON数据发送及解析的方法。通过实例演示了如何利用jQuery的$.post方法将JSON数据发送到服务器,并展示了如何在MVC中直接解析接收到的JSON数据为实体对象。

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

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

转载于:https://www.cnblogs.com/langu/p/3964261.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值