【发布时间】:2023-03-03 11:53:02
【问题描述】:
我正在尝试显示带有 ID + 名称 + 价格 的引导对话框。
然后如果用户在对话框中选择YES,它必须点击有删除功能的Action方法并刷新页面上的数据才能看到更改而不重新加载页面。
我也不希望在它点击删除用户操作方法后,它一定不能显示它的视图。
我尝试使用以下代码中的 ViewBag,但它没有在 Bootstrap 对话框中显示 ID + Name + Price,并且没有t 重定向到删除操作方法,并且不刷新页面
@model IEnumerable<School.Models.ApplicationUser>
<hr>
<table class="table table-responsive table-hover">
<tbody>
@foreach (var item in Model.OrderBy(x => x.DateTime))
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</td>
<td>
<span style="color: #ff0000;">
<a class="btn btn-warning btn-sm disclaimer-dialog">
<i class="fa fa-unlock"> </i>Delete
ViewBag.MyId = @item.Id;
</a>
</span>
</td>
@ViewBag.MyId
</tr>
}
</tbody>
</table>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/Scripts/Views/SchoolAccounts/Delete.js")
}
<!-- Button trigger modal -->
<!-- Modal -->
<div class="modal fade" id="disclaimerModalDialog" tabindex="-1" role="dialog" aria-labelledby="exampleModalScrollableTitle" aria-hidden="true" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="exampleModalScrollableTitle">Confirmation Deletion</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p><strong>Are you sure you want to reset password for user ? @ViewBag.MyId </strong></p>
@using (Html.BeginForm("DeleteProduct", "SchoolAccounts",
FormMethod.Post, new
{
@id = "delete-form",
role = "form"
}))
{
@*@Html.HiddenFor(m => m.Id)
@Html.AntiForgeryToken()*@
}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
onclick="$('#delete-form').submit();">
Yes
</button>
<button type="button" class="btn btn-primary"
data-dismiss="modal">
No
</button>
</div>
</div>
</div>
</div>
Delete.js 的内容
$(function () {
$('.disclaimer-dialog').click(function () {
$('#disclaimerModalDialog').modal('show');
});
});
【问题讨论】:
-
请附上
Scripts/Views/SchoolAccounts/Delete.js的代码 -
@JerdineSabio 我包含了它。
-
等一下,我正在创建一个答案。为了澄清,模态正确打开对吗?只是显示ID不行?
-
请在您的循环中包含名称和价格列,谢谢。
-
@JerdineSabio 事实上,除了我想在 ViewBag 的模式上显示的 ID + 名称 + 价格之外,一切都正确显示,包括模式。
标签: javascript jquery asp.net-mvc knockout.js