User665608656 posted
Hi jsshivalik,
According to the code you provided, when you pass parameters using ajax, you change contentType
at this time.
$. ajax contentType and dataType. contentType mainly sets the format you send to the server, and dataType sets the format you receive from the server.
Get and post are the most common HTTP requests. In jQuery's ajax, contentType is the default value: application/x-www-form-urlencoded.
The feature of this format is that name / value becomes a group, and each group uses & connection, while name and value use = connection.
Here you only pass the one parameter, so you don't need to add contentType to change the type.
The JSON.stringify() method converts a JavaScript object or value to a JSON string, optionally replacing values if a replacer function
is specified or optionally including only the specified properties if a replacer array is specified.
You can change your code like this:
function Delete(UsrName) {
var ans = confirm("Are you sure you want to delete this Record?");
if (ans) {
$.ajax({
url: '/Home/DeleteUser',
data: { UsrName: UsrName },
type: "POST",
// contentType: "application/json;charset=UTF-8",
dataType: "json",
success: function (result) {
loadData();
},
error: function (errormessage) {
alert(errormessage.responseText);
}
});
}
}
Here is the result you can refer :

Best Regards,
YongQing.