它显示错误"operator '==' cannot be applied to operands of type 'string' and 'int' " "where(x =>


    [HttpGet]
    public ActionResult EmployeeView(int id)
    {
        Employee employee = new Employee();
        using (HRMSEntities employeeContext = new HRMSEntities())
        {
            employee = employeeContext.Employee.Where(x => x.Person_Id == id).FirstOrDefault();
        }
        return View(employee);
    }
}

尝试id.ToString(),如果这不起作用:

string idAsString = id.ToString();

然后x => x.Person_Id == idAsString

主要问题是您可能不应该将您希望成为整数值的内容存储为字符串。除此之外,这里有一些选项:

x => Convert.ToInt32(x.Person_Id) == id

x => x.Person_Id == id.ToString()

最新更新