2016-05-26 7 views
0

bereits an get value from Html.TextBoxFor und an mehreren anderen Orten erhalten.Second Form Action, wie man einen Wert von Html.TextBoxFor

Ich möchte den Benutzernamen an einen verlorenen Passwort-Bildschirm übergeben. Ich habe name = "bjh" und id = "bjh" als Namen hinzugefügt, die sonst nirgendwo verwendet würden. Ursprünglich verwendete ich Username den Wert aus meinem Modell (m.Username). Die normale Anmeldung funktioniert, Werte werden übergeben, aber mein Passwort vergessen link @ LangStrings.LostPassword nicht erhalten den Benutzernamen Wert von @ Html.TextBoxFor (m => m.Username, neu {style = "width: 100%", id = "bjh" name = "bjh"})

Anmeldung 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> 
} 

-Controller

[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); 
    } 

Antwort

0

Ändern des href um slig htly in der Ansicht löste das Problem, verwendete Javascript und Jquery, um den Wert zu erhalten.

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