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; }
- }
- public ActionResult Index()
- {
- List
emplist = new List () { - 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();
- }
- @{
- ViewBag.Title = "Index";
- }
Index
@((ViewBag.totalemp as IEnumerable )) - @foreach (var item in ViewBag.totalemp)
- {
- @item.Id
- @item.Name
- @item.Designaton
- }
Arvind KushwahaPosted Jun 7, 2020, 6:42 AM
Arvind KushwahaPosted Jun 7, 2020, 6:57 AM
rahul patilPosted Jun 7, 2020, 6:54 AM