码迷,mamicode.com
首页 > 其他好文 > 详细

控制器post参数接收

时间:2018-03-07 19:07:12      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:csharp   turn   create   ring   log   get   char   div   stat   

1.后台c#

public class TestController : ApiController
{
        [HttpPost]
        public string SaveData1(Tb_a ota)
        {
            return ota.aa.ID + ota.bb.FirstOrDefault().NAME;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ota"></param>
        /// <returns></returns>
        [HttpPost]
        public bool SaveData(Tb_a ota)
        {
            return true;
        }
}
 public class Tb_a
    {
        public TB_CHARGING aa { get; set; }
        public List<TB_CHARGING> bb { get; set; }
    }

 2.前端js

var postData = { ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" };
 var postData1 = [{ ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" }, { ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" }];
        
$.ajax({
                type: "post",
                url: ApiUrl + "api/Test/SaveData",
                data: { aa: { ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" }, bb: [{ ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" }, { ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" }] },
                success: function (data, status) { }
            });


            $.ajax({
                type: "post",
                url: ApiUrl + "api/Test/SaveData1",
                data: { aa: postData, bb: postData1 },

                success: function (data, status) {
                    alert(data);
                }
            });

  

控制器post参数接收

标签:csharp   turn   create   ring   log   get   char   div   stat   

原文地址:https://www.cnblogs.com/liuqiyun/p/8523844.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!