2015-03-30 54 views
1

這是我的控制器。我有一個列表格式的看法,但它給錯誤:將數據綁定到列表中MVC控制器

Cannot implicitly convert type 'System.Collections.Generic.List' to 'MvcDemo.Models.Employee' G:\MvcApp\MvcDemo\MvcDemo\Controllers\EmployeeController.cs 18

public ActionResult Details() 
    { 
     EmployeeContext ec = new EmployeeContext(); 
     Employee e1 = ec.employee.ToList(); 


     return View(e1); 
    } 

我怎樣才能解決這個問題?

回答

2

將其更改爲如下所示。

public ActionResult Details() 
{ 
    EmployeeContext ec = new EmployeeContext(); 
    List<Employee> e1 = ec.employee.ToList(); 


    return View(e1); 
} 
+0

非常感謝你的先生! – 2015-03-30 19:02:40

相關問題