am using jquery code to popup my view.i хочу удалить данные через это всплывающее окно ... Но, используя следующий код, только всплывающее окно не выполняет удаление действия, отображается код jquery ниже.delete view using popup in mvc3
$(document).ready(function(){
$('.del').click(function (e) {
e.preventDefault();
custom_confirm('pleaseNote:',
function() {
var sel = $(this).attr('href');
$.ajax({
url: '/default1/Delete/',
type: 'POST',
data: { id: sel },
success: function (result) {
$(this).remove();
}, error: function (result) {
alert("error");
}
});
});
});
function custom_confirm(prompt, action, title) {
$("#confirm").dialog({
buttons: {
'Proceed': function() {
$(this).dialog('close');
$('#confirm').dialog({ modal: true });
action();
},
'Cancel': function() {
$(this).dialog('close');
}
}
});
}
})
и мой взгляд код
@Html.ActionLink("Delete","Delete",new { id = item.studentID }, new { @class="del"})
<div id="confirm" style="display: none"></div>
и действие контроллера
[HttpPost]
public ActionResult DeleteConfirmed(int id=0)
{
student student = db.students.Find(id);
if (student == null)
{
return HttpNotFound();
}
db.students.Remove(student);
db.SaveChanges();
return RedirectToAction("Index");
Аякса URL = URL: ' '/ Default1/Delete /',' но имя метода: 'DeleteConfirmed' –
Украсьте метод действий, как показано ниже. '[ActionName (« Удалить »)] public ActionResult DeleteConfirmed (int id = 0)' –
Не перекодируйте url, как этот 'url: '/ default1/Delete /'' он должен быть как '' Url.Action (" ActionName "," ControllerName ", new {area =" AreaName "})" ' –