POST多个参数到Web API控制器

交互基于Json的方式打包传递就不介绍了,主要设置请求头为

contentType: "application/json", //必须有

数据位Json格式的字符串,在服务器端定义对应的 数据结构的实体Model,然后就可以进行模型绑定了。

否则就使用老方式的纠结的Post的键值对接受解析;

public SendToClientMsgConteiner CalcReceiveClientProductPrice()//[FromBody]ViewModelForCalcProductPriceClient clientData)
{
SendToClientMsgConteiner msg = new SendToClientMsgConteiner();
try
{
string Id = System.Web.HttpContext.Current.Request.Form["Id"];
string Uuid = System.Web.HttpContext.Current.Request.Form["Uuid"];
string Items = System.Web.HttpContext.Current.Request.Form["Items"];
ViewModelForCalcProductPriceClient clientData = new ViewModelForCalcProductPriceClient()
{
Id = Id,
Uuid = Uuid
};
clientData.Items.AddRange(
JsonConvert.DeserializeObject<List<ViewModelForCalcProductItemClient>>(Items)
);

}

原文地址:https://www.cnblogs.com/micro-chen/p/4194198.html