【发布时间】:2017-07-28 06:33:55
【问题描述】:
我需要将员工详细信息保存到数据库。 我的想法是将员工数据从 Controller 以 json 格式发送到 reacjts,reactjs 应该调用 webapi post 方法。 Webapi 负责将数据保存在 sql server 中。
我的 web api 代码:
//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();
}
我的控制器:
[HttpPost]
public JsonResult CreateNew(Employee model)
{
return Json(model);
}
请提供一些建议,将我的员工模型发送到 reactjs。我是 reactjs 的新手。我试图将数据从控制器传递给 reactjs。
【问题讨论】:
-
你能详细说明你的问题吗?
-
我想将我的员工详细信息保存在 sql server 中。我已经使用 webapi 和实体框架创建了服务来将数据保存到 sql。现在我想从 reactjs 调用 webapi。我在控制器中以 json 格式获取员工信息。我只是想将此 json 数据发送到 reacjts 并调用 webapi。
-
它是由 Reacjts 完成的。我在 MVC 中使用 reactjs
标签: c# asp.net-mvc reactjs asp.net-web-api