我是 asp.net mvc 的新手。有了这个参考this。我正在使用元组将两个模型发送到一个视图中。我正在创建两个表单和两个提交按钮;但是当它是服务器时,值将变为空
@model Tuple<DAL.Models.LoginModel, DAL.Models.ForgotPassword>
@{
ViewBag.Title = "Login";
}
@using (Html.BeginForm("Login", "User", FormMethod.Post, new { ReturnUrl = ViewBag.ReturnUrl }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<ol>
<li>
@Html.LabelFor(m => m.Item1.EmailID)
@Html.TextBoxFor(m => m.Item1.EmailID, new { @id = "txt_login_EmailID" })
@Html.ValidationMessageFor(m => m.Item1.EmailID)
</li>
<li>
@Html.LabelFor(m => m.Item1.Password)
@Html.PasswordFor(m => m.Item1.Password)
@Html.ValidationMessageFor(m => m.Item1.Password)
</li>
<li>
<input type="submit" value="Login" id="btn_login" />
@Html.CheckBoxFor(m => m.Item1.RememberMe)
@Html.LabelFor(m => m.Item1.RememberMe, new { @class = "checkbox" })
</li>
</ol>
</fieldset>
}
这是同一页面中的另一个表单
@using (Html.BeginForm("ForgotPassword", "user"))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<ol>
<li>
@Html.LabelFor(m => m.Item2.EmailId)
@Html.TextBoxFor(m => m.Item2.EmailId, new { @id = "txt_fg_pwd_EmailID" })
@Html.ValidationMessageFor(m => m.Item2.EmailId)
</li>
<li>
<input type="submit" value="Reset Password" />
</li>
</ol>
</fieldset>
}
我的帖子方法是
[HttpPost]
public ActionResult Login(LoginModel LoginUser , string returnUrl)
{
if (LoginUser.IsValid)
{
SetAuthenticationCookie(LoginUser, LoginUser.RememberMe);
return RedirectToLocal(returnUrl);
}
else
{
ModelState.AddModelError("", "Incorrect user name or password .");
return View(LoginUser);
}
}
`
任何更改都需要查看或发布方法