zoukankan      html  css  js  c++  java
  • directly receive json data from javascript in mvc

    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.

  • 相关阅读:
    Android随笔
    Android随笔
    阅读笔记
    Android随笔
    Android随笔
    Android随笔
    Android随笔
    Java随笔
    Android随笔
    NC20265 着色方案(dp)
  • 原文地址:https://www.cnblogs.com/langu/p/3964261.html
Copyright © 2011-2022 走看看