Actually, I have this Method wich returns all fields of my table.
public ActionResult Index(string username, string searchString) { var UserLst = new List<string>(); var UserQry = from d in db.OrderDetails orderby d.Order.Username select d.Order.Username; UserLst.AddRange(UserQry.Distinct()); ViewBag.username = new SelectList(UserLst); var user = from m in db.OrderDetails select m; if (!String.IsNullOrEmpty(searchString)) { user = user.Where(s => s.Order.FirstName.Contains(searchString)); } if (string.IsNullOrEmpty(username)) return View(user); else { return View(user.Where(x => x.Order.Username == username)); } } [HttpPost] public string Index(FormCollection fc, string searchString) { return "<h3> From [HttpPost]SearchIndex: " + searchString + "</h3>"; }
My table looks like that :
Username———Product———-Price———-N°Cart
test————–Object1————-20———–110
test————–Object2————-84———–110
cloud————-Object2————-84———–541
Apple————-Object8————-65———–874
What I want is, when my user is log on and when he’s going to this page, he will see only rows with his username. In other words, I would like my method returns rows with the username of the logged in user.
Excuse me for my english, I wish you’ll understand me.
Thank you for your help, answers, links, I take all, I’m beginner in asp
If you are using ASP.NET Membership and joining on the Username field from your EF model then just call User.Identity.Name. If so, then you can remove the parameter from the method: