【发布时间】:2021-07-10 20:54:31
【问题描述】:
我正在使用 .NetCore 5 Entity Framework 来搜索我的数据。
当我发布数据时,我从 api 收到 400 错误 我的控制器:
public IActionResult Search( [FromBody]string data)
我的反应:
handleSubmit(event){
event.preventDefault();
const data = JSON.stringify({
searchTitle: this.state.searchTitle,
boolTitle: this.state.boolTitle,
boolSubject:this.state.boolSubject,
searchElement:this.state.searchElement,
refrence:this.state.refrence,
maker:this.state.maker,
subject:this.state.subject,
startTimeArea:this.state.startTimeArea,
endTimeArea:this.state.endTimeArea,
type:this.state.type,
isAvtive:this.state.isAvtive,
enacmentTime:this.state.enacmentTime
});
const headers = {
'Content-Type': 'application/json' ,
'Accept':'application/json'
}
axios.post('/api/searchPost/search',data,{
headers: headers
}).
then(result => console.log(result)).
catch((error) => {
console.log(error);
});
}
我尝试将 [fromBody] 更改为 [fromForm] 400 错误已修复,但控制器字符串中的接收值为 null
【问题讨论】:
-
我投票结束这个问题,因为 OP 之前也问过同样的问题。 stackoverflow.com/q/68321589/14072498
标签: c# reactjs asp.net-core