Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试将post方法从react js应用到asp.net时出错400_Asp.net_Reactjs_Post - Fatal编程技术网

尝试将post方法从react js应用到asp.net时出错400

尝试将post方法从react js应用到asp.net时出错400,asp.net,reactjs,post,Asp.net,Reactjs,Post,当我从用户那里获得输入时,我试图实现post方法,但是当我提交结果时。它显示结果是成功的,但它显示了一个400错误的错误请求 reactjs中的post方法: constructor(props){ super(props) this.state = { Order_ID: '', Name: '', Age: 0 } } changeHandler = e => { console.log(&quo

当我从用户那里获得输入时,我试图实现post方法,但是当我提交结果时。它显示结果是成功的,但它显示了一个400错误的错误请求

reactjs中的post方法:

 constructor(props){
    super(props)

    this.state = {
        Order_ID: '',
        Name: '', 
        Age: 0
    }
}


changeHandler = e => {
    console.log("Hello!")
    this.setState({ [e.target.name]: e.target.value })
}

submitHandler = e => {
    e.preventDefault()

    
    fetch('http://localhost:54507/api/customers',{
        method:'post',
        mode:'cors',
        headers:{
            'Accept':'application/json',
            'Content-Type':'application/json'
        },
        body:JSON.stringify({
           Order_ID:e.target.Order_ID.value,
           Name:e.target.Name.value,
           Age:parseInt(e.target.Age.value,10)
        })
    })
    .then(res=> res.json())
    .then((result)=>{
        alert('Success')
    },
    (error)=>{
        alert('Failed')
    }
    )
}
visual studio中的我的post方法:

 public HttpResponseMessage Post([FromBody] Customer customer)
    {
        try
        {
            using (PharamcyEntities entities = new PharamcyEntities())
            {
                entities.Customers.Add(customer);
                entities.SaveChanges();

                var message = Request.CreateResponse(HttpStatusCode.Created, customer);
                message.Headers.Location = new Uri(Request.RequestUri + customer.Order_ID.ToString());
                return message;
            }
        }
        catch (Exception ex)
        {
            return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
        }
    }
注意:我使用
[启用CORS(“*”、“*”、“*”)]
我能够从VisualStudio中将问题跟踪到实体; 请帮忙(