I am looking for assistance with submitting a form from an MVC view without refreshing the page. However, it seems that my AJAX code below is not functioning properly: //here is ajax call
function AjaxCallAndShowMessage(btnClick) {
$('form').submit(function () {
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function (result) {
ShowTimeChangeMessage(); // show an alert message
}
});
return false;
});
}
// here is the view
<div id="dialog" title="">
@using (Html.BeginForm("Administration", "Home", FormMethod.Post, new { enctype = "multipart/form-data"}))
{
@Html.DropDownList("SeTime", new List<SelectListItem>
{
new SelectListItem{ Text="1 Min", Value = "60" },
new SelectListItem{ Text="2 Min", Value = "120" },
new SelectListItem{ Text="3 Min", Value = "180" },
}, "Select Time")
<input type="submit" value="Set Time "
onclick="AjaxCallAndShowMessage(this)" />
}
</div>
I am unable to retrieve data for the selected item from the dropdown list "SetTime" in the controller. Can someone provide guidance on how to appropriately make the AJAX call for this view? Thank you.