获取System.NullReferenceException:

时间:2017-05-03 11:13:41

标签: .net asp.net-mvc model-view-controller

“对象引用未设置为对象的实例”在运行迁移时收到此错误这是Employee Model Service接口

    public IEnumerable<Employee> GetEmployees(string name)
    {
        return string.IsNullOrEmpty(name) ? UnitOfWork.EmployeeRepository.GetAll() : UnitOfWork.EmployeeRepository.GetAll().Where(c => c.Name == name);
    }

这是员工服务代码

    public JsonResult GetEmployees()
    {
        try
        {
            IEnumerable<Employee> employee = _employeeService.GetEmployees().ToList();
            IEnumerable<EmployeeListViewModel> viewModelListEmployee= 
       Mapper.DynamicMap<IEnumerable<Employee>, IEnumerable<EmployeeListViewModel>>(employee);
         return new JsonSuccessResult(viewModelListEmployee);

        }
        catch (Exception ex)
        {
            Response.StatusCode = (int)ResponseCode.UnprocessableEntity;
            return new JsonErrorResult(ex.ToString());
        }
    }

此员工控制器发生错误

onKeyDown = function(event){
          console.log('KEY: ' + event.which);
          if (event.which == 250 || event.which == 229) {
                event.preventDefault();
          }
      };

请有人详细说明为什么我从这段代码中得到这个错误???任何帮助将不胜感激。

0 个答案:

没有答案