2016-05-26 6 views
0

はすでにget value from Html.TextBoxForと他のいくつかの場所を見ています。第2フォームアクション、Html.TextBoxForから値を取得する方法

失われたパスワード画面にUserNameを渡したいとします。もともと私は私のモデル(m.Username)からの値をUsernameという名前で使用しましたが、名前= "bjh"とid = "bjh"を他の場所では使用されない名前として追加しました。 通常のログインが動作しますが、値は渡されますがパスワードを忘れた場合@ LangStrings.LostPasswordはユーザ名の値を @ Html.TextBoxFor(m => m.Username、new {style = "width:100%"、 ID = "BJH"、名前= "BJH"})

ログインVIEW

@model HelpDesk.Models.LoginUserModel 

@using (Html.BeginForm("Login", "User", new { ReturnUrl = Request.QueryString["ReturnUrl"] }, FormMethod.Post)) 
{ 
<table class="grey" > 
    <tr><td colspan="2"><h2>@LangStrings.Login 
      @if (Settings.AllowUserRegistration) { 
       <span class="grey"><span style="font-weight:normal">@LangStrings.Or</span> 
       <a href="@Url.Action("Register")">@LangStrings.Register</a></span> 
      } 
     </h2><div>@Html.ValidationSummary(false)</div></td></tr> 
    <tr> 
     <td><span style="font-size:14px">@LangStrings.Username @LangStrings.Or @LangStrings.Email</span></td> 
     <td><span style="font-size:14px">@Html.TextBoxFor(m => m.Username, new { style = "width:100%" ,id="bjh",name="bjh"})</span></td> 
    </tr> 

    <tr> 
     <td></td> 
     <td style="padding-top: 16px;"> 
      <input id="Login" type="submit" value="@LangStrings.Login" style="font-weight:bold; font-size:16px " /> 
      @if (Settings.EnableSaml) { <text><input type="submit" name="samlButton" class="graybutton" value="SAML Login" /></text> } 
     </td> 
    </tr> 
    <tr> 
     <td></td> 
     <td><a href="@Url.Action("LostPassword")" style="font-size:14px">@LangStrings.LostPassword</a> 
     </td> 
    </tr> 
</table> 
} 

コントローラ

[AllowAnonymous] 
    public ActionResult LostPassword(string bjh) 
    { 
     var a = bjh; 
     if (string.IsNullOrWhiteSpace(a)) 
      { 
       a = "empty"; 
      } 

     return View(new LostPasswordModel() { Email = a }); 
    } 

    [AllowAnonymous] 
    [HttpPost] 
    public ActionResult LostPassword(LostPasswordModel model) 
    { 
     if (model.Email.IndexOf("@") <0) 
      { 
       //not email, so clear found value 

      } 
     if (ModelState.IsValid) 
     { 
      if (!model.ResetPsw(Url.AbsoluteAction("Login", "User", null))) 
       ModelState.AddModelError(String.Empty, LangStrings.Email_not_found); 
      else 
       ModelState.AddModelError(String.Empty, LangStrings.Success__An_email_has_been_sent__Check_your_inbox_after_a_while_); 
     } 
     return View(model); 
    } 

答えて

0

slig周りHREFを変更しますビュー内のhtlyは、問題を解決し、値を取得するためにJavascriptとJavascriptを使用しました。

<a href="#" style="font-size:14px" onclick="window.location.href='@Url.Action("LostPassword")?bjh='+$('#bjh').val();">@LangStrings.LostPassword</a> 
関連する問題