0

我意识到这是非常简单的,但我想在使用时将文本框值传递给控制器​​方法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 返回一个空值。

我将如何正确地做到这一点?

阿里安

4

1 回答 1

4

我认为不需要传递单个字符串参数,而是可以从视图中传递整个模型

[HttpPost]
    public ActionResult GetPassword(YourModel yourmodel)
    {
        ViewModel model = new ViewModel();

        model.VerifyUserExists(yourmodel.EmailForgotPassword);
        return View(model);
    }
于 2013-12-19T07:29:31.410 回答