Click here to Skip to main content
15,915,864 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Here is my controller code..


C#
public class DetailsController : Controller
    {
        //
        // GET: /Details/
                 

        List<Employee> employees = new List<Employee>();
        List<Department> departments = new List<Department>();
 
        public ActionResult Index()
        {
            employees.Add(new Employee { DepartmentID = 1, EmployeeID = 1, EmployeeName = "Kailas" });
            employees.Add(new Employee { DepartmentID = 2, EmployeeID = 2, EmployeeName = "Dipak" });
            employees.Add(new Employee { DepartmentID = 2, EmployeeID = 3, EmployeeName = "Pramod" });
            employees.Add(new Employee { DepartmentID = 1, EmployeeID = 4, EmployeeName = "Prakash" });
            employees.Add(new Employee { DepartmentID = 3, EmployeeID = 5, EmployeeName = "Pranav" });
            employees.Add(new Employee { DepartmentID = 4, EmployeeID = 6, EmployeeName = "Dipesh" });

            departments.Add(new Department { DepartmentID = 1, DepartmentName = "IT" });
            departments.Add(new Department { DepartmentID = 1, DepartmentName = "BA" });
            departments.Add(new Department { DepartmentID = 1, DepartmentName = "CS" });
            departments.Add(new Department { DepartmentID = 1, DepartmentName = "MBA" });
            departments.Add(new Department { DepartmentID = 1, DepartmentName = "Comm" });

            var list = (from e in employees
                        join d in departments
                        on e.DepartmentID equals d.DepartmentID
                        select new { 
                            EmployeeName = e.EmployeeName,
                            DepartmentName = d.DepartmentName
                        }).ToList();

            return View(list);
        }
	}
Posted

Read any "getting started" tutorial on MVC or read any book on MVC and these basic topics will be covered. A forum is not a good place to learn something from scratch.
 
Share this answer
 
Hi,

you have pass anonymous object rather then that pass in some of the class like by changing below linq type as

@model IEnumerable<mvc4webapp.models.employee.employeeviewmodel>


@foreach (var item in Model)
{
}

Employee Name
Department Name
@item.EmployeeName
@item.DepartmentName



here i have create object object class and i have define department name in it.

after that with below code you can define your view.

i.e

@model IEnumerable<mvc4webapp.models.employee.employeeviewmodel>


@foreach (var item in Model)
{
}

Employee Name
Department Name
@item.EmployeeName
@item.DepartmentName


so with above code you can run it very well and if you need more help then start leaning with basic mvc

http://www.c-sharpcorner.com/UploadFile/deveshomar/simple-way-of-binding-list-of-objects-to-view-using-mvc/[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900