Note that there are some explanatory texts on larger screens.

plurals
  1. POform is always submit using get method MVC4
    text
    copied!<p>i m trying to login from a dropdown on navigation bar but when i click on <code>signin</code> button the form is submited as get method although i defined <code>FormMethod.Post</code> but still it is submited using get method and all the values are visible in <code>QueryString</code> here is my code and image <img src="https://i.stack.imgur.com/Vmyz8.png" alt="enter image description here"></p> <p>and after clicking <code>Signin</code> <img src="https://i.stack.imgur.com/uSMM0.png" alt="enter image description here"></p> <p><strong>CODE:</strong></p> <pre><code> @using(Html.BeginForm("Login","Auth",FormMethod.Post,null)) { @Html.TextBoxFor(m=&gt;m.Email,new{@style = "margin-bottom: 15px;",@placeholder = "Email address",@size = "30",@type = "email",@required = ""}) @Html.PasswordFor(m=&gt;m.Password,new{@style = "margin-bottom: 15px;",@placeholder = "Password",@size = "30"}) @Html.CheckBoxFor(m =&gt; m.RememberMe, new { @style = "float: left; margin-right: 10px;" }) @Html.LabelFor(m=&gt;m.RememberMe) &lt;input class="btn btn-primary" style="clear: left; width: 100%; height: 32px; font-size: 13px;" type="submit" value="Sign In" /&gt; } </code></pre> <p><strong>CONTROLLER CODE</strong></p> <pre><code>[HttpGet] public ActionResult Login(string returl) { if (!User.Identity.IsAuthenticated) { ViewBag.returl = returl; return View(); } string[] arr1 = System.Web.Security.Roles.GetRolesForUser(User.Identity.Name); foreach (var v in arr1) { if (v.Contains("Administrator")) { return RedirectToAction("Index", "Admin"); } else { return RedirectToAction("Index", "Home"); } } return RedirectToAction("Index", "Home"); } [HttpPost] public ActionResult Login(Login log, string returl) { if (ModelState.IsValid &amp;&amp; Membership.ValidateUser(log.Email, log.Password)) { if (((MyMembershipProvider)Membership.Provider).IsActive(log.Email)) { FormsAuthentication.SetAuthCookie(log.Email, log.RememberMe); string[] arr = System.Web.Security.Roles.GetRolesForUser(log.Email); if (returl != null) { foreach (var v in arr) { if (v.Contains("Administrator")) { return RedirectToAction("Index", "Admin"); } else { return Redirect(returl); } } } else { foreach (var v in arr) { if (v.Contains("Administrator")) { return RedirectToAction("Index", "Admin"); } else { return RedirectToAction("Index", "Home"); } } } } else { ModelState.AddModelError("", "Please confirm ur email to Login!!!!"); } } else { ModelState.AddModelError("", "Incorrect username or password!!!"); } return View(); } </code></pre> <p><strong>SOLUTION:</strong> the error was being caused because the main page contain a form tag in which partial view is rendered which causes it to redirect to home page(index function)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload