I am trying to understand fetching in Reactjs
I simply want to pass a string value to my React project
Please help me out
Controller:
- namespace reacttest.Controllers
- {
-
- public class TestingController : Controller
- {
- [HttpGet("New")]
- public string New()
- {
- string Name = "Jon";
- return Name;
- }
- }
- }
ReactJS:
- import { data } from 'jquery';
- import React, { Component } from 'react';
-
- export class New extends Component {
- static displayname = New.name;
-
- constructor(props) {
- super(props);
- this.state = {
- Names1 : "nothing"
- };
- }
- componentDidMount() {
- fetch('reacttest/TestingController/New')
- .then(Response => (Response.json())
- .then(data => { this.setState({ Name1: data }) })
- }
-
- render() {
- return (
- <h1>my name = {this.state.Names1} </h1>
- )
- }
- }
it just returns "Nothing"