문제

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