I have a one to many relationship of Users to Certificates. In my view I am able to see all data from Certificates and related data from Users. However this view gives me a repeat of UserID and is not effective. Please see this question here first.
In this view I used this query
var certUser = var cert = db.Certificates.Include(c => c.Users);
var AllcertUser = from s in certUser select s;
return View(AllcertUser.ToList());
Since UserID is distinct from this controller with this LINQ code:
var Allusers = from s in db.Users
select s;
return View(Allusers.ToList());
I get distinct Users from the code above. When I try to include from Certificates class, this is where I am failing to make it work. I need to include the Certificates so that I can have values from that entity which are related. I hope I made myself clear.
This is part of what I need. When Details are clicked the UserID must be passed and their details shown. At the moment I have hard coded id 23. How to pass the user id to the details view so that I get the certificates details.
public ActionResult Details(int id)
{
cpdEntities db = new cpdEntities();
var UserCerts = db.Certificates.Where(x => x.UserID == 23).ToList();
return View(UserCerts);
}