I want to display a list data form controller to view
I m getting error:
student.cs
- public class Employee
- {
- public int Id { get; set; }
-
- public string Name { get; set; }
-
- public string Designaton { get; set; }
-
- }
HomeController.cs
- public ActionResult Index()
- {
- List<Employee> emplist = new List<Employee>() {
- new Employee(){ Id=1, Name="Steve", Designaton = "hr" },
- new Employee(){ Id=2, Name="Bill", Designaton = "finance" },
- new Employee(){ Id=3, Name="Ram", Designaton = "hr" },
- new Employee(){ Id=4, Name="Ron", Designaton = "finance" },
- new Employee(){ Id=5, Name="Rob", Designaton = "finance" }
- };
-
- ViewBag.totalemp = emplist.Count();
-
- return View();
- }
Index.cshtml
- @{
- ViewBag.Title = "Index";
- }
- <h2>Index</h2>
- <td>@((ViewBag.totalemp as IEnumerable<migrationdemo.Models.Employee>))</td>
- @foreach (var item in ViewBag.totalemp)
- {
- @item.Id
- @item.Name
- @item.Designaton
- }
I want to displaying all data but now i am facing error?