有一个页面主要用于显示 WebGrid (MVC 5) 和用于编辑行的 Bootstrap 3.0.2 模式 (jQuery 2.0.3)。只是一个小问题...对话框不仅会在我单击一行时出现,而且在我单击列标题中的排序链接和寻呼机链接时也会出现。理想情况下,我希望能够区分触发 ajaxUpdateCallback 的原因,以便我可以有条件地在回调处理程序中显示模式。
这是我认为的代码...
@using School.Models
@model IEnumerable<Course>
@{
ViewBag.Title = "Courses";
}
<h2>@ViewBag.Title</h2>
@{
var grid = new WebGrid(Model, rowsPerPage: 15, ajaxUpdateContainerId: "gridContent", ajaxUpdateCallback: "webGridUpdated");
}
<div id="gridContent">
@grid.GetHtml(htmlAttributes: new { id = "grid", @class = "table table-striped table-hover table-condensed" },
columns: grid.Columns(
grid.Column("Name", header: string.Format("Name {0}", grid.SortColumn == "Name" ? grid.SortDirection == SortDirection.Ascending ? "▼" : "▲" : ""),
format: @<text>@item.GetSelectLink(item.Name)</text>),
grid.Column("Active", header: string.Format("Active {0}", grid.SortColumn == "Active" ? grid.SortDirection == SortDirection.Ascending ? "▼" : "▲" : ""),
format: (item) =>
{
var course = item.Value as Course;
return Html.DisplayFor(modelItem => course.Active);
}
)
)
)
@if (grid.HasSelection)
{
@Html.Partial("Edit", (Course)grid.SelectedRow.Value)
}
else // New Course
{
@Html.Partial("Create", new Course() { })
}
</div>
<script type="text/javascript">
function webGridUpdated() {
// Would like to be able to wrap this in a conditional
$('#EditModal').modal('show');
}
</script>