[英]How to send data from react to Controller in ASP.NET MVC?
I am new to react. 我是新来的。 I am trying to build a CRUD application with React and .NET MVC.
我正在尝试使用React和.NET MVC构建一个CRUD应用程序。 I am able to find the code for only getting content from controller, but not for posting.
我能够找到仅用于从控制器获取内容而不能用于发布的代码。
Below is the code for getting data from controller: 下面是从控制器获取数据的代码:
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>
);
}
});
Please provide me the code to send data from react to controller. 请提供代码以将数据从反应发送到控制器。
My data class: 我的数据类:
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; }
}
As mentioned in the comments, sent the data using How to make a rest post call from ReactJS code? 正如评论中提到的,使用如何从ReactJS代码中进行剩余发布调用来发送数据?
Now create an action in your controller 现在在您的控制器中创建一个动作
[HttpPost]
public void GetInfo([FromBody]EmployeeTable data){
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.