I have a button which calls a function onClick and passes a couple of parameters. I need to use AJAX to pass these two parameters to the controller and onsuccess do something client-side. Here's the button and the ajax call:
<button type="button" class="btn btn-default" onclick="addComponent(@item.ID, @item.VendorID)">Add</button>
function addComponent(componentId, vendorId) {
$.ajax({
type: 'POST',
url: '@Url.Action("WriteSupportComponent")',
contentType: false,
dataType: 'json',
data: { "componentId": componentId, "vendorId": vendorId },
success: function (response) {
console.log('returned success');$('#' + componentId).remove();
console.log('removed tr');
},
error: function (ex) {
console.log('returned failed: ' + ex.responseText);
}
});
}How do I need to structure the controller to do something (write to db in this case) and then return success or failed back to the function?
Thanks in advance
Adam