我意识到这是非常典型的,但我想在使用Html.BeginForm
这是我到目前为止所尝试的内容
CSHTML
@using (Html.BeginForm("GetPassword", "Home"))
{
<div id="panEmailForgotPassword">
<h3 style="margin: 0;">
Please enter your email address</h3>
<br />
<table style="width: 57%; padding-bottom: 10px; height: 126px;">
<tr>
<td>
<label style="width: 110px;">
Email address:</label>
</td>
<td>
@Html.TextBoxFor(m => m.EmailForgotPassword, new { name = "txtEmailForgotPassword" })
</td>
</tr>
控制器方法
[HttpPost]
public ActionResult GetPassword(string txtEmailForgotPassword)
{
ViewModel model = new ViewModel();
model.VerifyUserExists(txtEmailForgotPassword);
return View(model);
}
txtEmailForgotPassword返回空值。
我该如何正确地做到这一点?
阿里安
答案 0 :(得分:3)
我认为不需要传递单个字符串参数,而是可以从视图中传递整个模型
[HttpPost]
public ActionResult GetPassword(YourModel yourmodel)
{
ViewModel model = new ViewModel();
model.VerifyUserExists(yourmodel.EmailForgotPassword);
return View(model);
}