当我 return 在 ASP.NET MVC 中从控制器数据局部视图时如何调用模态
How to call a modal when I return data a partial view from the controller in ASP.NET MVC
我有一个控制器,其中 return 部分视图中的数据,我想调用模态,如何实现?
我把我的控制器的详细信息留给你,并在下面查看。
控制器
[HttpPost]
public async Task<ActionResult> Items(List<string> items)
{
var dto = new ItemsDetails();
dto.item = items;
return PartialView($"~/Views/Items/ItemDetails.cshtml", dto);
(Here I want to call a modal)
}
查看
这就是我要调用的模式。
<!-- Modal -->
@model Application.ItemsDetails
<div class="modal fade" id="items" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
您使用 javascript 打开模式。
那应该是一个 bootstrap 模态。
为了 select 你的模式很容易,你应该给它一个 id
像这样:
<div class="modal fade" id="myModal">
然后将此脚本放在文件的底部
<script type="text/javascript">
$('#myModal').modal('show');
</script>
为此,必须先加载 JQuery 和 Bootstrap。css 和 .js 文件。如果这些加载到页面底部,您将需要延迟脚本调用,直到页面完全加载。
可在此处找到更多信息:
https://getbootstrap.com/docs/4.0/components/modal
如果它不工作,请检查浏览器控制台是否有错误 (F12)
我有一个控制器,其中 return 部分视图中的数据,我想调用模态,如何实现?
我把我的控制器的详细信息留给你,并在下面查看。
控制器
[HttpPost]
public async Task<ActionResult> Items(List<string> items)
{
var dto = new ItemsDetails();
dto.item = items;
return PartialView($"~/Views/Items/ItemDetails.cshtml", dto);
(Here I want to call a modal)
}
查看 这就是我要调用的模式。
<!-- Modal -->
@model Application.ItemsDetails
<div class="modal fade" id="items" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
您使用 javascript 打开模式。
那应该是一个 bootstrap 模态。
为了 select 你的模式很容易,你应该给它一个 id
像这样:
<div class="modal fade" id="myModal">
然后将此脚本放在文件的底部
<script type="text/javascript">
$('#myModal').modal('show');
</script>
为此,必须先加载 JQuery 和 Bootstrap。css 和 .js 文件。如果这些加载到页面底部,您将需要延迟脚本调用,直到页面完全加载。
可在此处找到更多信息: https://getbootstrap.com/docs/4.0/components/modal
如果它不工作,请检查浏览器控制台是否有错误 (F12)