2
Reply

Getting an Error while adding a strongly typed view

Sthitaprajnya Debasis Nayak

Sthitaprajnya Debasis Nayak

Feb 20 2016 12:29 PM
485
Hi Friends !!!
 
please help me out.
 
Model class 
 

[Table("tbl_Employee")]

public class Employee

{

[key]

public int EmpID { get; set; }

public string Name { get; set; }

public string Gender { get; set; }

public string City { get; set; }

}

controller class Action Methode
 

public ViewResult HyperLink()

{

EmployeeDBContext objEmployeeDbContext = new EmployeeDBContext();

List<Employee> Employees = objEmployeeDbContext.Employees.ToList();

return View(Employees);

}

While I am trying to add a Strongly typed view to this Action method I am getting an error like below
 
MVCDemo.Models.Employee:: Entity type "Employee" has no key defiened. Define the key for this entity type ."
 
 

Answers (2)