POST多个参数到Web API控制器
2014-12-30 17:55
120 查看
交互基于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)
);
}
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)
);
}
相关文章推荐
- 模拟浏览器http post 请求,把参数传到控制器
- Laravel之路由 Route::get/post/any、路由参数、过滤器、命名、子域名、前缀、与模型绑定、抛出 404 错误、控制器
- 控制器post参数接收
- SSM 控制器POST方法接参数出现乱码
- WebApi系列~实际项目中如何使用HttpClient向web api发异步Get和Post请求并且参数于具体实体类型
- post提交到controller控制器参数乱码问题
- web api中post参数时只能一个
- WebApi系列~实际项目中如何使用HttpClient向web api发异步Get和Post请求并且参数于具体实体类型
- MVC5的控制器,使用HttpPost方式时,接收的参数为null的原因
- Restful Web Api Get 和 Post 请求的参数设置
- Web APi之捕获请求原始内容的实现方法以及接受POST请求多个参数多种解决方案(十四)
- ajax xmlhttp下open方法POST、GET参数的区别
- 对于web api 从页面post数据到web api,如果用ajax,则可以成功上传到服务器,需要一个类来存储那些变量
- Android利用post方式给webview传递json参数
- Xutils的参数设置post、get
- 解决Fiddler查看Post参数中文乱码的问题
- 解决springMCV后台接收不到AngularJ的$http.post参数的方法
- 使用jQuery.Ajax向ASP.NET MVC控制器Post数据
- 远程带参数POST访问接口,返回数据
- #nodejs post或get 请求获取参数