I'm new to ASP.NET MVC. I'm trying to update model on button click with no success: every time I push the button an HttpGet controller method is invoked.
Here is my markup
@model DataInterface.Model.Entry
<button onclick="location.href='@Url.Action("Survey")'">Finish survey</button>
Here is Controller code
[HttpGet]
public ActionResult Survey()
{
var entry = new Entry();
return View(entry);
}
[HttpPost]
public ActionResult Survey(Entry newEntry)
{
// save newEntry to database
}
When I click button HttpGet method is invoked. Why?
It is bad to be a rookie) Thanks to all!
Surveymethod in your controller. The browser will send a get request to it and process the response. The easiest way to send aPOSTrequest is by submitting a form.