【发布时间】:2017-10-07 13:08:10
【问题描述】:
我有这个 AngularJS Http 调用
$http({
method: "POST",
url: Helper.ApiUrl() + '/Api/Case/SendCase',
data: { obecttype1, obj2, obj3},
}).then(function mySuccess(response) {});
Ant 这个 ASP.net Web Api 方法
[HttpPost]
[Route("Api/Path/SendCase")]
public int SendCase(object application)
{
string applicantName = ((Newtonsoft.Json.Linq.JObject)application)["applicant"].ToString();
obecttype1 obj = JsonConvert.DeserializeObject<obecttype1>(((Newtonsoft.Json.Linq.JObject)application)["obecttype1"].ToString());
.........................
return ID;
}
这很好用,但我觉得它有点脏,因为我在我的方法中解析我的对象,所以我的问题是
是在 POST 方法中将多个对象作为参数发送的方法吗,我宁愿避免修改我的模型,避免为此创建一个类
所以我的 Api 方法看起来像这样
public int SendCase(class1 obecttype1, class2 obj2, class3 obj3)
【问题讨论】:
-
如果不创建一个新类来保存
objecttype1、obj2和obj3,您将无法做到这一点。
标签: angularjs asp.net-mvc asp.net-web-api