所以我只希望允许登录用户为他们自己预订假期。我认为最简单的方法是在个人表中比较登录用户的“名称”和“名称”。所以....
public ActionResult Create()
{
string xx = (string)Session["usernameID"];
int? currentPersonID = Convert.ToInt32(xx);
string userNameComparedAgainstLoginName = // here is where i want to say 'name' of logged in user
CreateModel model = new CreateModel();
model.currentPersonID = currentPersonID.Value;
model.PList4DD = db.People.ToList();
if (userNameComparedAgainstLoginName == model.userName)
{
ViewBag.Id = new SelectList(db.People, "Id", "Name");
return View(model);
}
else
{
TempData["canOnlyBookHolidaysForYourself"] = "I'm afraid you can only book holidays for yourself";
return RedirectToAction("Index");
}
}
用户注册时给出的名称将与数据库中使用的名称相同。
那么有人可以告诉我如何访问登录的“名称”吗?
谢谢