I have to make an AJAX call on the onchange event of a dropdownlist which is part of a view. On the change event i need to call the database, do some calculations display th
Ok, if what you want ia a way to call a onchange event when a dropdownlist change this can be helpful:
@Html.DropDownListFor(
model => model.SelectedId,
new SelectList(ViewBag.Ids, "Id", "Name"),
"[All]",
new { onchange = "onChangeId();", @id ="municipalityDropDown" }
)
then you can have this javascript code and you ajax code. And here is an example of a jax code to call a action method.
function onChangeId() {
jQuery.ajax({
url: '@Url.Action("Action Method Name", "Controller Name")',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({ data: data2 }),
success: function (result) { }
});
}