Answered by:
button click dosent submit to post method.

Question
-
User739135361 posted
public class LoginController : Controller
{
[HttpGet]
public ActionResult ForgotPassword()
{
ViewBag.fpMessage = null;
return View();
}
[HttpPost]
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>@ViewBag.fpMessage</label>
}
else
{
<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
Answers
-
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.
https://www.w3schools.com/tags/ref_httpmethods.asp
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" /> }
https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/getting-started
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, October 21, 2019 3:59 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" />
</form<
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.
https://www.w3schools.com/tags/ref_httpmethods.asp
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" /> }
https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/getting-started
- 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