Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hello,

I am using Entity Framework and I have only one Table which is "Voiture". I didn't create a table User.

I tried to show the Data that are related to the logged User used this code in the Controller but it doesn't work :

What I have tried:

C#
public ActionResult Index()
{

var userId = (int)Session["userId"];
return View(voi.Where(t => t.ID == userId).ToList());

}
Posted
Updated 22-Aug-17 22:44pm
Comments
Richard Deeming 15-Aug-17 14:24pm    
"It doesn't work" doesn't give us enough information to help you.

Click "Improve question" and update your question with a proper description of the problem. Include the full details of any compiler errors or exceptions, and remember to tell us which line of code they relate to.

If you're just not getting any records, then you're going to need to debug your code to ensure that the userId is correct, and that there are actually some records in your database for that user.

1 solution

To capture logged user data in mvc, you can use iprincipal concept to capture the logged user information such as userid, name, first name etc
1. When user login in capture the required information and save in iprincipal
basically iprincipal save the information in cookies
2. You can access the information on controller as well as view
with following syntax:
HttpContext.Current.User as MyCustomPrincipal
 
Share this answer
 

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