2013-04-25 131 views
0

我有第一個表單中的用戶名和密碼,並以另一種形式檢索密碼,其中我想要第一個表單中的第一個表單提交的第二個表單中的userame。如何在另一個表單中提交表單值提交

@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中捕獲隱藏字段中的用戶名,但不工作。 或者可以在窗體內形成用於實現此目的。 請提供解決方案。

感謝,

Michaeld

+0

JavaScript是可能的方式來做到這一點。讓我們看看你的JavaScript。 – Jasen 2013-04-25 17:46:24

+0

嗨Jasen,謝謝你的輸入document.getElementById('username')。value = document.getElementById('Username')。value;工作我試圖改變隱藏價值編號名稱 – michaeld 2013-04-25 17:51:43

回答

0

在在「Stundent」控制器「指數」行動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; 
} 

這將解決您的問題。

+0

第二ALT變得爲空,因爲兩者都是在不同的形式,dint有很多時間來測試與formcollection解決方案,謝謝 – michaeld 2013-04-25 18:15:29