我是新来的反应。我正在尝试使用React和.NET MVC构建一个CRUD应用程序。我能够找到仅用于从控制器获取内容而不用于发布的代码。
下面是从控制器获取数据的代码:
var App = React.createClass({
getInitialState: function(){
return{data: ''};
},
componentWillMount: function(){
var xhr = new XMLHttpRequest();
xhr.open('get', this.props.url, true);
xhr.onload = function() {
var response = JSON.parse(xhr.responseText);
this.setState({ data: response.result });
}.bind(this);
xhr.send();
},
render: function(){
return(
<h1>{this.state.data}</h1>
);
}
});
请提供代码以将数据从反应发送到控制器。
我的数据类:
public partial class EmployeeTable
{
public int EmployeeID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Gender { get; set; }
public string Designation { get; set; }
public long Salary { get; set; }
public string City { get; set; }
public string Country { get; set; }
}
最佳答案
如注释中所述,使用How to make a rest post call from ReactJS code?发送数据
现在在您的控制器中创建一个动作
[HttpPost]
public void GetInfo([FromBody]EmployeeTable data){
}
关于javascript - 如何将数据从响应发送到ASP.NET MVC中的Controller?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47298702/