public class JsonParamModel
    {
        /// <summary>
        /// json key
        /// </summary>
        public string JsonKey { get; set; }

        /// <summary>
        /// json object
        /// </summary>
        public dynamic JsonObj { get; set; }
    }
  [HttpPost]
        public Result WebapiDynamic(JsonParamModel json)
 $.ajax({
                type: "POST",
                contentType: "application/json",
                dataType: "json",
                url: $("#url").val(),
                data: JSON.stringify({"JsonKey": "13", "JsonObj": { "Key1": "11", "Key2": "-10" } }),
                success: function (results) {
                    if (typeof results == "object") {
                        JSON.stringify(results);
                    }
                    else {
                        var resultObj = JSON.parse(results);
                    }
                   

                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.responseText);
                }
            });


总结:在实体或者直接在参数中采用dynamic可以动态的接收参数

但是ajax在调用的时候稍微有一点不同

data: JSON.stringify({"JsonKey": "13", "JsonObj": { "Key1": "11", "Key2": "-10" } }),

contentType: "application/json",

 

相关文章:

  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-18
  • 2021-04-16
相关资源
相似解决方案