zoukankan      html  css  js  c++  java
  • web api中post参数传递

    post

    1. string int double等
    2. dynamic(非跨域)
    3. 实体类
    4. JObject(推荐)
    5. JArray
     1.string int double等

    [Route("xx"), HttpPost]
         public void Post([FromBody]string value)
         {
         }

    2.dynamic

     后台接收

    [HttpPost]
    [Route("Batchbook")]
    public IHttpActionResult Batch_book(dynamic obj)
    {
    string group_id = Convert.ToString(obj.group_id);
    string group_name = Convert.ToString(obj.group_name);
    string ids = Convert.ToString(obj.ids);

    }

    3.实体类

    [Route("AddConfirm"), HttpPost]
    public IHttpActionResult AddConfirm(ry_rectify_confirm model)

    4.JObject

    ajax: 

    data: JSON.stringify(data),

    public IHttpActionResult AddReservation(JObject obj) {
    var vm = obj.ToObject<EnterApplyViewModel>();

    }

    5.JArray

    前台

    var index = layer.load(1, {
    shade: [0.1, '#fff']
    });
    var list = [];
    $(".checkinfo").each(function (j, curr) {
    if (j >= 0 && $(curr).find('input[name="ischeckIn"]').is(':checked')) {
    var data = $(curr).serializeObject();

    if ($(".group").length > 0) {

    data["group_id"] = $(curr).children().find('.group').val();
    if ($(curr).children().find(".group").attr('case_no') != undefined)
    data["group_name"] = $(curr).children().find(".group").attr('case_no');
    else
    data["group_name"] = "";
    }
    list.push(data);
    }
    });

    $.ajax({
    type: "post",
    contentType: "application/json;charset=utf-8",
    url: url,
    data: JSON.stringify(list),
    dataType: "json",
    success: function (data) {
    if (data.success) {
    layer.msg('操作成功!', { time: 500, anim: 0 }, function () {
    window.history.go(-1);
    });
    }
    else {
    layer.msg(data.message);
    layer.close(index);
    }
    },
    error: function (result, status) {
    layer.msg('服务器连接失败');
    }
    });

    实体类接收datetime时会忽略时分秒 所以改用JArray

    [HttpPost]
    [Route("addcheckin")]
    public IHttpActionResult Add_checkin(JArray obj)
    {
    List<rm_checkin> model = obj.ToObject<List<rm_checkin>>();

    }

  • 相关阅读:
    第04组 Alpha冲刺 总结
    第04组 Alpha冲刺 (6/6)
    软工实践个人总结
    第09组 每周小结 (3/3)
    第09组 每周小结 (2/3)
    第09组 每周小结 (1/3)
    第09组 Beta冲刺 总结
    第09组 Beta冲刺 (5/5)
    第09组 Beta冲刺 (4/5)
    第09组 Beta冲刺 (3/5)
  • 原文地址:https://www.cnblogs.com/yyjspace/p/11653777.html
Copyright © 2011-2022 走看看