Using axios.post for send a simple value int to my controller on asp.net core, when send any value ever the method controller receive value "0".
Which is the correct way for send this type of value using axios (post or delete)?
PD: i can send correctly models and receive on controller with [FromBody]
Method controller:
[Route("Delete"),HttpPost]
public async Task<ActionResult> Delete(int id)
{
try{
var result = await userService.DeleteUserPerson(id);
return Json(new{
response=true,
data=result,
error=""
});
}
catch(Exception ex){
return Json(new{
response=false,
data=false,
error=ex.Message
});
}
}
Method from react class:
async function DeleteUser(id, props){
var request= new Request({});
try{
console.log(id);
var axiosResp= await request.axios_request.post('User/Delete', JSON.stringify({id:id}));
if(axiosResp.status!=200){
//do smething
}
//this case validate error
if(axiosResp.data.response && !axiosResp.data.error){
//do something
}
//do something
}catch(err){
//do something
}
}
Class request (axios):
export default class Request {
constructor(){
this.axios_request = axios.create({
baseURL: 'http://localhost:5000/api',
timeout: 5000,
headers: authHeader()
});
}
}