Dear Sir,
My name is Ajay Sutar. I am newly learning MVC 4, as we are about to initiate a new project in ASP .NET MVC 4. I am using a details scaffolding to display a single record. but now my single employee have multiple roles. As example,
Emp_no | Role | Salary
E1 | Software Engineer | 10000
E1 | Tester | 10000
as i have used Details scaffold and FirstOrDefault method of linq for this view, I am unable to display the second role "Tester" in the output. only first role is geeting displayed.
What i want is :
Emp_no : E1 Role: Software Engineer Salary:10000
Tester
Anupam SinghPosted Jul 3, 2014, 4:06 AM
you can create a viewmodel for this .
ex.
class Employee
{
Employee()
{
Roles = new List
}
public int ID {get;set;}
public List
public int Salary {get;set;}
}
// then fill view model using linq or lambda query(depends on approach you are following).
Employee emp=new Employee();
// bind roles using
emp.Roles = (from a in context.Employee where a.id==_id select a.Roles).ToList();
// bind rest of the properties as usual.