0
votes

already looked at get value from Html.TextBoxFor and several other places.

I want to pass the UserName to a lost password screen. I added name="bjh" and id="bjh" as names that would not be used elsewhere, originally I used Username the value from my model (m.Username). The normal login works, values get passed but my forgot password link @LangStrings.LostPassword doesn't get the username value from @Html.TextBoxFor(m => m.Username, new { style = "width:100%" ,id="bjh",name="bjh"})

Login 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);
    }
1

1 Answers

0
votes

Changing the href around slightly in the view solved the problem, used javascript and Jquery to get the value.

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