I am trying to pass values from angular to a web api.

Currently what I have for angular which does communicate with the webapi since I have it counting when something connects to it.

var data = new FormData();
data.append("x", "1");
data.append("y", "2");
$scope.http({ method: 'PUT', url: urltowebapi, data: data });

What I have on the webapi side is supposed to read the values but it always comes back as {}.

HttpContent req = Request.Content;
string str = req.ReadAsStringAsync().Result; 

没有正确的解决方案

其他提示

Somehow I got it.

In angluar I am passing the data.

$scope.http({ method: 'PUT', url: controllerurl, data: { data: data } });

And in my controller I read it and deserialize the json. I think it was how I had the angular passing the data before but I don't know.

HttpContent req = Request.Content;
string str = req.ReadAsStringAsync().Result; 
var jObj = (JObject)JsonConvert.DeserializeObject(str);
string data= jObj["data"].ToString();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top