reactjs - How to perfrom WEBAPI Post call from react Js? -
its asked question. still didnt clear. have call post method of webapi in reactjs. have created model in webapi. want know how pass model data post call in reactjs.
model :
public class employeemodels { public int id { get; set; } public string name { get; set; } public string mobile { get; set; } public string email { get; set; } public string dept { get; set; } public string erole { get; set; } }
my webapi post method :
//insert new employee public ihttpactionresult createnewemployee(employeemodels emp) { using (var ctx = new employee()) { ctx.tempemp.add(new tempemp() { id = emp.id, name = emp.name, mobile = emp.mobile, erole = emp.erole, dept = emp.dept, email = emp.email }); ctx.savechanges(); } return ok(); }
now should want post employeemodel reactjs. kindly give suggestions.
i have given answer:
let employee={ id:1, name:'abc', mobile:123456, email:'abc@abc.com', dept:'it', role:'developer' } fetch('https://mywebsite.com/createnewemployee/', { method: 'post', headers: { 'accept': 'application/json', 'content-type': 'application/json', }, body: json.stringify(employee) }) .then(function(resp){ // response })
Comments
Post a Comment