Struggling to establish communication between the view and controller for updating values in the database using JavaScript, MVC, and Asp.Net. Here is a snippet of my view:
function updateRejectType() {
$("#btnvalider").click(function () {
var IdRTDoc = <%: ViewData["IdRTDoc"] %>;
var strDocumentType=<%: ViewData["RejectedTypesList"] %>;
var strLabel= <%: ViewData["strLabel"] %>;
$.ajax({
type: "GET",
url: '<%= Url.Action("UpdateRejectedType", "RejectedTypes") %>',
data: "IdRTDoc=" + IdRTDoc +"DocumentType"+ strDocumentType + "Label" + strLabel,
processData: false,
cache: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
complete: function () {
alert("updated");
},
success: function (result, request) {
alert("Mis à jour avec succès");
SuccessValider();
},
error: FailureFunction,
failure: FailureFunctionUpdate
});
});
}
function SuccessValider(){
window.open('../Home/About', '_parent');
}
function FailureFunctionUpdate() {
alert("Problème survenu dans update !");
}
`
which contains the function
updateRejectType() that I call here
<input type="button" class="lien_bloc_gris" onclick="updateRejectType()" value="valider" name="btnvalider"><span> </span></a></input>
And here is my controller method
public virtual ActionResult UpdateRejectedType(int IdRTDoc, int strDocumentType, string strLabel)
{
try {
RejectedTypesViewModel obj = new RejectedTypesViewModel();
obj.DocumentType = strDocumentType;
obj.Label = strLabel;
var result = repository.RejectedTypesUpdate("All", obj);
return null;
} catch (Exception ex) {
return RedirectToAction("Error", "Shared");
}
}
Clicking on the button does not seem to trigger any action. What steps can be taken to resolve this issue?