TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mad Man
NA
2
898
Code Not Working when Switch To AJAX From Formaction
Jun 24 2018 5:06 AM
I am trying to call an MVC controller method to delete a selected jqGrid row using AJAX instead of using the form's formaction attribute on a view but thus far it is not working.
When I use formaction to call my controller method everything worked fine but it did not implement a confirm modal which asks users to confirm if they really want to delete the selected grid row.
Thus, I want to use a confirm modal in conjuction with AJAX to call my controller method. Below is the form code in my MVC view.
@
using
(Html.BeginForm(
"Delete"
,
"CustomerForms"
, FormMethod.Post))
{
<div>.....</div>
<div>.....</div>
<button
class
=
"btn"
id=
"Delete"
type=
"submit"
formaction=
"DeleteRecord"
formmethod=
"post"
name=
"command"
value=
"Delete"
>Delete </button>
}
The controller method DeleteRecord takes no input parameter so I thought I can just set the formaction =" #" and then call the controller method using AJAX like the following inside
$(
"#Delete"
).click(
function
(e) {
e.preventDefault();
$(
"#DeleteDialog"
).dialog(
"open"
);
});
$(
"#DeleteDialog"
).dialog({
height: 280,
modal:
true
,
autoOpen:
false
,
buttons: {
'Confirm'
:
function
() {
$.ajax({
type:
"POST"
,
cache:
false
,
url:
"/CustomerForms/DeleteRecord"
,
success:
function
(data) {
alert(
"Deleted!"
);
}
});
$(
this
).dialog(
'close'
);
},
'Cancel'
:
function
() {
$(
this
).dialog(
'close'
);
}
}
});
@{
var
message = ViewBag.Message;}
@
if
(message ==
"Deleted"
)
{
ViewBag.Message =
null
;
jQuery(
"#jQGrid"
).clearGridData(
true
).trigger(
"reloadGrid"
);
jQuery(
'#jqGrid'
).trigger(
'reloadGrid'
);
$(
'#files'
).empty();
}
Normally if everything had worked successfully, the script below the delete dialog would run, the viewBag value would be set to null, and the jqGrid would reload resulting in the deletion of the selected grid row.
However, when I click the Delete button, the controller is executed like it's supposed to but the script below the delete dialog is skipped and doesn't get executed.
Reply
Answers (
1
)
Password is in plain text in ASP.Net Page submit.
Asp.net MVC Razor Posting and binding of interface