我的模特是
public class Login
{
[Required]
[Display(Name = "Email")]
[EmailAddress]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
}
我的帖子方法是
[HttpPost]
public ActionResult Login(Models.Login lu)
{
using (travelAndTourismEntities objentity = new travelAndTourismEntities())
{
if (ModelState.IsValid)
{
if (IsValid(lu.Email, lu.Password))
{
FormsAuthentication.SetAuthCookie(lu.Email, true);
return RedirectToAction("Home", "jettravel");
}
else
{
ModelState.AddModelError("", "Login details are wrong.");
}
}
return View(lu);
}
}
在视图中
@if (Request.IsAuthenticated)
{
<div class="col-md-3 col-sm-3 col-xs-12" style=" font-size:14px; ">
<div class="header_info">
<p class="login_username">Welcome <span>@Html.Encode(User.Identity.Name)</span></p>
}
我想在视图中显示客户电子邮件,但@if(Request.IsAuthenticated)总是变错
答案 0 :(得分:1)
尝试替换此行
<p class="login_username">Welcome <span>@Html.Encode(User.Identity.Name)</span></p>
与
<p class="login_username">Welcome <span>@HttpContext.Current.User.Identity.Name;</span></p>