When using ASP. NET Web APIs, you want the parameters to be of the List <t> type,
It is known that Web APIs support parameters in JSON format, such as {key1: value1, key2: value2}, and the object parameters passed to the function, for example:
public Class MyClass{public string key1{get;set;}public string key2{get;set;}}...public Class BLL_GetValue{ [HTTPPost] public void GetValue(MyClass c){ ... }}...$.ajax({ type: 'post', url: '/api/BLL_GetValue/GetValue', data: JSON.Stringify({ 'key1': value1, 'key2': value2 }), dataType: 'json', success: function (data) {}})
However, if the getvalue method is as follows:
[HttpPost]public void GetValue(List<MyClass> c){ ...}
It cannot be solved. I don't know if there is any solution.
So detour:
Let the method accept the JSON string, convert it to an object using JSON. net, and pass it to the method call.
using Newtonsoft.Json;using Newtonsoft.Json.Converters;using Newtonsoft.Json.Linq;...List<Model_WI_SEARCH_CONDITION> list = new List<Model_WI_SEARCH_CONDITION>(); JArray o; o = JsonConvert.DeserializeObject<JArray>(searchConditon); foreach (var item in o) { Model_WI_SEARCH_CONDITION c = new Model_WI_SEARCH_CONDITION(); c.WI_LIST_ID = Convert.ToDecimal(item["WI_LIST_ID"].ToString()); c.MI_OPTIONS_TYPE_ID = Convert.ToDecimal(item["MI_OPTIONS_TYPE_ID"].ToString()); c.MI_OPTIONS_ID = Convert.ToDecimal(item["MI_OPTIONS_ID"].ToString()); list.Add(c); }...