【发布时间】:2016-08-01 16:47:02
【问题描述】:
我被这个问题困住了,一直在敲我的脑袋,这似乎很可行也很容易,但现在没有点击。
我有一个MVC6 视图,它由各种partials 组成。
在其中一个部分上,假设我有一个 anchor 标签:
@model ModelA
<div>
@Html.TextBoxFor(m=>m.Id)
<a onclick="BookProduct();" style="pointer:cursor">Book Product</a>
</div>
<div id="divModalBody" class="modal fade" tabindex="-1" role="dialog">
<div id="divModalPopup">
</div>
</div>
<script>
function BookProduct()
{
$.ajax({
url:'Controller1/BookProduct',
type:'GET',
dataType:'html',
data:SOME SAMPLE DATA,
success:function(result)
{
if(result!=undefined)
{
$("divModalBody").html(result);
}
},
error:function(xhr)
{
console.log(xhr);
}
});
}
</script>
这个BookProduct() 函数基本上调用controller 方法并通过AJAX call 在modal popup 中显示结果。
我在那个popup中执行了一些操作,然后点击Save。
数据经过验证并保存到数据库中,控件返回到success part of the modal popup。
I then close the popup and need to refresh the partial of the parent page and maybe bind it to a list.
如何让我的父页面了解popup 工作已经完成,现在需要刷新partial view?
请指导。
【问题讨论】:
-
你能分享一下你的弹窗成功的部分吗?您应该能够访问那里的 DOM 并使用 ajax 重新加载部分视图。
-
@Shyju..显然上面只是一个示例代码,弹出窗口及其代码是由一位开发人员开发的,它位于一个单独的 js 文件中,坦率地说我不知道帽子有被写在弹窗的成功部分。我不确定我是否可以在那里访问我的 DOM。但是,如果您对如何执行它提供一些指示,我明天会尝试,因为我现在无法访问 TFS。谢谢
-
您应该能够访问 DOM,因为弹出框通常会附加到同一页面。
-
@Shyju..好吧,我明天试试..所以在弹出窗口的成功部分,我必须重新加载包含部分视图的 div?我不太确定,因为我的部分视图接受的模型和弹出窗口成功部分中的返回类型可能不同......任何指针?
-
调用ajax获取部分视图内容,你可以使用jQuery load方法来实现。看看Refresh table using AJAX in ASP.NET MVC
标签: javascript jquery ajax asp.net-mvc popup