Master_T Master_T - 5 months ago 21
ASP.NET (C#) Question MVC form submission always calls GET action instead of POST

I have a form in MVC that looks like this:

<div class="x_content">

<form id="elementEditForm" class="form-horizontal form-label-left">

<input type="hidden" name="returnUrl" value="@ViewBag.returnUrl" />

... my form fields....

<div class="form-group">
<div class="col-md-9 col-md-offset-3">
<button type="submit" form="elementEditForm" class="btn btn-success">Submit</button>

And in the controller I have:

public ActionResult Edit(string id, string returnUrl = null)
var e = getEditModel(id);
return View("GenericElementEdittView", e);

public ActionResult Edit(string id, object evm, string returnUrl = null)

return View();

My problem is that the
method is not called when I click the button to submit the form. Instead, the
method gets called every time, resulting in the page just reloading instead of submitting.

What am I doing wrong?

Answer Source

GET is the default method when none is specified. Specify the POST method:

<form id="elementEditForm" class="form-horizontal form-label-left" method="post">