I am trying to call a controller method "GetTasksList" onchange of dropdown value in view. However onchange of dropdown, the "Edit" method of Controller is being called and submitting the form to database. This is undesirable because I am trying to fetch a list of tasks from the database based on the dropdownvalue.
View
@Html.DropDownListFor(x => x.AuditDecision, (SelectList)ViewBag.ListofAuditDecision, "Please select", new { @class = "form-control input-10", id = "AuditStatus", onchange = "testing();", @style = "width: 300px;" })
function testing() {
alert("in testing");
document.forms[0].action = 'GetAuditTasksList';
// window.location.href = 'GetAuditTasksList';
document.forms[0].submit();
}
The control goes to below method
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(Audit audit)
{
//submitting to database
}
instead of
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult GetAuditTasksList(Audit audit)
{
}