Click here to Skip to main content
14,208,035 members
Rate this:
 
Please Sign up or sign in to 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:

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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
   

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



Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190612.1 | Last Updated 23 Aug 2017
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100