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
            };
        }

 

posted on 2019-09-11 13:30  漫思  阅读(2464)  评论(1编辑  收藏  举报

导航