I have a DeleteUser function that gets called when user clicks on the delete row icon in an actioncolum.
Here is the code for the function:
function DeleteUser(id) {
Ext.Ajax.request ({
url: 'user/delete/castle',
params: {id: id},
success: function (result,request){
Ext.MessageBox.alert('Success', result.responseText);
},
failure: function (result, request){
alert(result.responseText);
}
});
}
Right now, when a user is deleted, a pop-up appears with the title “Success” but the result.responseText parameter is empty.
I need the result.responseText parameter to be “User deleted successfully” but I need to pass that by using RenderText in the delete function that gets called via the url.
Here is the code for the delete function that gets called via the url ‘user/delete/castle’:
public void Delete (int id){
CancelView();
CancelLayout();
User user = User.FindUser(id);
user.Delete();
RenderText(JsonConvert.SerializeObject(???));
}
Does anyone have any tips as to how to do this? I am new to Ajax requests and JSON.
Thanks for the help.
You have to return a JSON object like
to client.
Here is the way to do it:
Server code:
To notify a failure you can set
success = falsein above code.Client code: