zoukankan      html  css  js  c++  java
  • contentType: 'application/json' C#后台怎么处理

    1. contentType: 'application/json' 的处理如下:

      $(function () {
                $.ajax({
                    'url': "/Home/Send2SHengPi",
                    data: JSON.stringify({"WorkId":[1, 2, 3, 4, 5]}),
                    contentType: 'application/json',
                    type: "post",
                    success: function (data) {
                        if (data.suc) {
                            layer.msg('提交成功', { icon: 1 })
                            t1.draw(true);
                        }
                        else {
                            layer.msg(data.remark, { icon: 2 })
                        }
    
                    }
                })
            })

    我们后台怎么对应呢?

      public class S1
        {
          public int[] WorkId { get; set; }
        }
    public ActionResult Send2SHengPi(S1 s1)
            {
                return new JsonResult()
                {
                    Data = new { id = "日前", name = "wre" },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
    
            }

     2、对于复杂点的常规的就是这样。

    <script>
            $(function () {
                $.ajax({
                    'url': "/Home/WorkExes1",
                    data: { "WorkId": JSON.stringify([1, 2, 3, 4, 5])},
                    //contentType: 'application/json',
                    type: "post",
                    success: function (data) {
                        if (data.suc) {
                            layer.msg('提交成功', { icon: 1 })
                            t1.draw(true);
                        }
                        else {
                            layer.msg(data.remark, { icon: 2 })
                        }
    
                    }
                })
            })
    
    
        </script>

    后台的业务逻辑

      public ActionResult WorkExes1(string WorkId)
            {
    
                return new JsonResult()
                {
                    Data = new { id = "日前", name = "wre" },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
            }
  • 相关阅读:
    基础数据类型补充、集合、深浅拷贝
    python中(id,is,==,)小数据池,代码块
    字典:python的基础数据类型
    五四青年节后记
    test
    agl---atumotive grade linux开篇
    传感器
    金字塔原理
    写在2017年底
    C# 输出16进值
  • 原文地址:https://www.cnblogs.com/sexintercourse/p/11505761.html
Copyright © 2011-2022 走看看