user1186050 user1186050 - 11 months ago 81
Ajax Question

javascript or ajax to update database with mvc?

I have a function here from a change event on a dropdownlist. When the selection gets changed I want to update a row in my database. Should I use javascript or ajax. I don't want the page to be refreshed. I think it should be ajax, but not sure? If ajax, can anyone point me to a tutorial/video/etc?

Here is where I want to update my db row.

var statusdropdown = document.getElementById("enumstatus");
statusdropdown.addEventListener("change", function(event) {
// call db and update row
}, false);

Answer Source

Looks like you using mvc.

You can write your ajax calls with pure javascript Ajax docs or the easiest way, using JQuery.

You need to add one action on your controller to receive the ajax data, and then insert/update your db.

See this, this and this.