【发布时间】:2011-10-31 00:37:47
【问题描述】:
将这个 sn-p 从控制器中取出,例如:
public ActionResult Login()
{
if (User.Identity.IsAuthenticated)
{
return RedirectToAction("Index", "Home");
}
else
{
return View();
}
}
//
// POST: /User/Login
[HttpPost]
public ActionResult Login(LoginModel lm, string returnUrl)
{
if (ModelState.IsValid)
{
if (Membership.ValidateUser(lm.UserName, lm.Password))
{
FormsAuthentication.SetAuthCookie(lm.UserName, lm.RememberMe);
if (Url.IsLocalUrl(returnUrl) &&
returnUrl.Length > 0 &&
returnUrl.StartsWith("/") &&
!returnUrl.StartsWith("//") &&
!returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "Username and Password combination is incorrect");
}
}
return View();
}
我的问题是,对于Login()(用于HTTP POST)的重载方法,第一个参数为LoginModel 类,第二个参数为string 的方法是什么?我的 Login.cshtml 视图使用了提交按钮,所以我很好奇这些参数是如何传递给 Login() 方法的?是什么阻止我添加第三个参数?以及该参数如何传递??
我知道这是一个基本问题,我只是想了解视图和控制器之间的连接部分。
【问题讨论】: