[英]Receive Angular2 POST with ASP.net
I have this method: 我有这种方法:
gotoDispatch() {
//
const headers = new Headers();
headers.append('Content-Type', 'application/json');
var url = 'Users/Cards';
var dto = { 'jsonSearchCards': 'testing' };
return this.http.post(GlobalVariables.SITE_ROOT + url, dto, { headers })
.subscribe(function (data) {
console.log('received response');
});
}
In my ASP.net controller I have: 在我的ASP.net控制器中,我有:
var currentForm = Request.Form["jsonSearchCards"];
var from = Request.Params["jsonSearchCards"];
but both receive null? 但都收到空值? What do I need to do?
我需要做什么?
Create an object on the .NET side that matches the object you're sending from JavaScript. 在.NET端创建一个与您从JavaScript发送的对象匹配的对象。
public class TheRequest
{
public string JsonSearchCards { get; set; }
}
Then make that the parameter to your API method. 然后将该参数设为您的API方法。
This is an ASP.NET question, not an Angular 2 one. 这是一个ASP.NET问题,而不是Angular 2问题。
Just add the variables to signature of your controller method: 只需将变量添加到控制器方法的签名即可:
public IHttpActionResult FindParts(string JsonSearchCards)
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.