0

我有第一种形式的用户名和密码,并以另一种形式检索密码,我希望在提交第二种形式时以第一种形式输入用户名。

 @model Network.Models.LoginDetail

    <script type="text/javascript">

    </script>
    @{
        ViewBag.Title = "Index";
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    <p>
        Please enter your user name and password. @Html.ActionLink("Register", "Register") if you don't have an account.
    </p>

    @using (Html.BeginForm("Index","Student",FormMethod.Post)) {
     <div>
            <fieldset>
                <legend>Account Information</legend>

                <div class="editor-label">
                @Html.LabelFor(model => model.Username)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Username)
                @Html.ValidationMessageFor(model => model.Username)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.Password)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Password)
                @Html.ValidationMessageFor(model => model.Password)
            </div>
            <p>
            <input type="submit" value="Log in" style="width: 200px"/>
            </p>
            @ViewBag.Message
            </fieldset>
             </div>
            }
            @using (Html.BeginForm("RetrievePassword","Student",FormMethod.Post)) {
            <p>
            Forgot password? <input type="submit" onclick="updateUsername();"value="Click Here" style="width: 150px"/> Entering your username to retrieve your password.
            </p>
            @Html.HiddenFor(model => model.Username)
        }   

我们如何才能做到这一点,我尝试在隐藏字段中捕获用户名的 javascript 但不起作用。或者可以使用形式中的形式来实现这一点。请提供解决方案。

谢谢,

迈克尔德

4

1 回答 1

0

在“Student”控制器中的“Index”操作的 post 方法中,您将能够以 formcollection 或 LoginDetail 对象形式获取值。

例子:

public ActionRestult Index(FormCollection FC)
{
   string UserName = FC["Username"];
   string Password = FC["Password"];
}

或者

public ActionRestult Index(LoginDetail obj)
{
   string UserName = obj.Username;
   string Password = obj.Password;
}

这将解决您的担忧。

于 2013-04-25T17:53:28.383 回答