Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 它在“其中(x=>x.person\u id==id)”中显示一个错误“运算符'=='不能应用于'string'和'int'类型的操作数”_C# - Fatal编程技术网

C# 它在“其中(x=>x.person\u id==id)”中显示一个错误“运算符'=='不能应用于'string'和'int'类型的操作数”

C# 它在“其中(x=>x.person\u id==id)”中显示一个错误“运算符'=='不能应用于'string'和'int'类型的操作数”,c#,C#,如果id.ToString不起作用,请尝试: 字符串idAsString=id.ToString 然后x=>x.Person\u Id==idAsString主要问题是,您可能不应该将期望为整数值的内容存储为字符串。除此之外,还有一些选择: x=>Convert.ToInt32x.Person\u Id==Id x=>x.Person\u Id==Id.ToString您可以发布员工类定义吗?请格式化您的代码,Person.Person\u Id的类型是什么?根据错误消息,它是一个字符串。为什么

如果id.ToString不起作用,请尝试:

字符串idAsString=id.ToString


然后x=>x.Person\u Id==idAsString

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

x=>Convert.ToInt32x.Person\u Id==Id


x=>x.Person\u Id==Id.ToString

您可以发布员工类定义吗?请格式化您的代码,Person.Person\u Id的类型是什么?根据错误消息,它是一个字符串。为什么字符串和int之间的比较应该起作用?或者:为什么要在字符串中存储整数值?可能是
    [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);
    }
}