1

I am new to react. I am trying to build a CRUD application with React and .NET MVC. 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; }
    }
4
  • check this stackoverflow.com/questions/38510640/… Commented Nov 15, 2017 at 4:14
  • how to obtain the transferred data in the controller? Commented Nov 15, 2017 at 4:54
  • do you have a class that contains the structure of the data you want to pass? Commented Nov 15, 2017 at 5:11
  • @NevilleNazerane yes. Ill include the class in the question. Commented Nov 15, 2017 at 5:16

1 Answer 1

1

As mentioned in the comments, sent the data using How to make a rest post call from ReactJS code?

Now create an action in your controller

[HttpPost]
public void GetInfo([FromBody]EmployeeTable data){

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.