Не могу отображать данные с помощью reactjs
Как я могу отображать свои данные с помощью reactJS? что я сделал не так?
Что я уже пробовал:
Контроллер
<pre>public class EmployeeController : Controller { private IUnitOfWork _dataBase; private IMapper<Employee, EmployeeViewModel> _employeeMapper; public EmployeeController(IUnitOfWork dataBase, IMapper<Employee, EmployeeViewModel> employeeMapper) { _dataBase = dataBase; _employeeMapper = employeeMapper; } public ActionResult Index() { return View(); } public JsonResult Get() { var employees = _dataBase.Employees.GetAll(); var employeesVM = new List<EmployeeViewModel>(); foreach (var employee in employees) { var employeeVM = _employeeMapper.Map(employee); employeesVM.Add(employeeVM); } return Json(employeesVM, JsonRequestBehavior.AllowGet); } }
JSX
<pre>class Employee extends React.Component { constructor(props) { super(props); this.state = { employees: props.employee }; } render() { return <div> <p>{this.state.employees.Name}</p> </div>; } } class Employees extends React.Component { constructor(props) { super(props); this.state = { employees: [] }; } render() { return <div> { this.state.employee.map(function (employee) { return <Employee employee={employee} /> <p>Hello</p> }) } </div>; } } ReactDOM.render( <Employees url="/employee/getall" />, document.getElementById("content") );
Смотреть
<pre>@{ Layout = "~/Views/Shared/_Layout.cshtml"; } <html> <head> <title>Employee</title> </head> <body> <div id="content"></div> <script src="~/Scripts/jquery-3.3.1.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script> <script src="@Url.Content("~/Scripts/employee.jsx")"></script> <script src="~/Scripts/react/react.min.js"></script> </body> </html>