编辑项目模式弹出窗口asp.net mvc

时间:2020-08-12 13:34:38

标签: javascript ajax asp.net-mvc

我尝试使用以下示例:MVC 5 Edit Bootstrap Modal Popup 我有Index页,在其中发送了onclickEdit(id)页,还有Edit页,其中放置了我的模式html。

.js:

{     
var id = $(elem).data('assigned-id');     
alert("1");     
$.ajax({         
url: '/Course/Edit/id=' + id,         
success: function (data) {             
alert("2");             
$('#modalWrapper').html(data);             
$('#editModal').modal();         
}     
}); 
}

警报(“ 1”)有效,警报(“ 2”)无效。

控制器:

public IActionResult Edit(Guid id)         
{             
return PartialView(_courses.Find(id));         
}

我检查了一下,我进入了Edit(),它通过了,但是我没有成功实现ajax 我应该改变什么? 非常感谢

1 个答案:

答案 0 :(得分:0)

好像您在'show'函数中缺少字符串输入modal()。通过添加它,它将使模态可见。

$('#editModal').modal('show');

Bootstrap文档: https://getbootstrap.com/docs/4.1/components/modal/#modalshow

更新

$.ajax({
        url: '/Course/Edit/id=' + id,
        type: 'GET',
        cache: false,
        success: function (result) {
            alert("2");
            $('#modalWrapper').html(result);             
            $('#editModal').modal('show');  
        }
    });

更新

您在Chrome浏览器的开发控制台中是否遇到任何错误?按F12即可访问它。

enter image description here

相关问题