I have a Major model like this:
public int Id { get; set; }
public string MajorName{ get; set; }
public string Password { get; set; }
public System.DateTime RegisterDate { get; set; }
public string StudentId { get; set; }
public string State { get; set; }
public int FacultyId { get; set; }
public int MajorId { get; set; }
public HttpPostedFileBase ImgFile { get; set; }
So I have a method like this in my repository for the above model:
public Major FindMajorById(int id)
{
return _dbcontext.Majors.Find(id);
}
In my view I passed the id and I need the name of major:
<td>
@{
EducationRepositor.MajorRepository objmajor=new MajorRepository();
}
@Html.DisplayFor(objmajor.FindMajorById(modelItem => int.Parse(item.MajorId)).MajorName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Degree)
</td>
But I get error in my view in this line:
@Html.DisplayFor(objmajor.FindMajorById(modelItem => int.Parse(item.MajorId)).MajorName)
My error:
argument type lambda expression is not assignable to parameter type int
FindMajorByIdmethod takes anint, and you're providing a lambda expression. What do you expect that to do? - Jon Skeet