button click dosent submit to post method. RRS feed

  • Question

  • User739135361 posted

    public class LoginController : Controller     



    public ActionResult ForgotPassword()         


         ViewBag.fpMessage = null;              

         return View();         



    public ActionResult ForgotPassword(FormCollection fc)         


             /// Some Logic 

            ViewBag.fpMessage = "Email Has been sent to your registerd email address. Please Check.";              

             return View();         



    ******************* View **********


    @if (ViewBag.fpMessage != null && ViewBag.fpMessage != "") 







    <label>Enter your User Name: </label>

    <input type="text" name="UserName" class="txt" />

    <input type="button" value="Recover Password" class="button button1"  onclick="location.href='@Url.Action("ForgotPassword", "Login")'" />


    Is their some issue with this code?

    Button click dosent post to Post method ForgotPassword. Its ubmits to get method Whats wrong?

    I have tried with Begin From, but with no luck.

    Monday, October 21, 2019 2:50 PM


All replies

  • User-29703693 posted

    Have you tried using a form tag and getting rid of onclick=?

    <form asp-action="ForgotPassword">

    <input type="text" name="UserName" class="txt" />

    <input type="button" value="Recover Password" class="button button1"  />


    Monday, October 21, 2019 3:13 PM
  • User475983607 posted

    The button is coded to send an HTTP GET not POST.

    <input type="button" value="Recover Password" class="button button1"  onclick="location.href='@Url.Action("ForgotPassword", "Login")'" />

    Use a standard HTML form to submit a POST.


    The Razor coding pattern is...

    @using (Html.BeginForm("ForgotPassword", "login")) {
        <label> Enter your User Name: </label>
        <input type = "text" name = "UserName" class="txt" />
        <input type="submit" value="Recover Password" class="button button1" />


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 21, 2019 3:59 PM
  • User739135361 posted

    this worked tanks :)

    Tuesday, October 22, 2019 3:22 AM