我一直在使用 Visual Studio 在 MCV 3 中创建一个视频游戏网站,并且无法弄清楚如何将我的页面中的 ID 传递到弹出对话框以从我的数据库中显示正确的开发人员。
我现在要放置的页面是我用来执行基本 CRUD 的 DeveloperManager 页面,我正在尝试执行的功能是当我单击删除链接以打开一个对话框,要求确认应删除该开发人员,然后将其删除。
我已经有一个页面调用 DeveloperManager/Delete,如果我现在只是单击正在传递item.DeveloperID
,它会显示正确的开发人员并在确认后将其删除。但只是为了方便,我想在对话框中打开该页面。
正如您将看到的那样,当我单击“创建新”按钮时,我已经设法打开了一个对话框,但它不使用参数只是打开页面创建了一个开发人员并关闭它。
这是 DeveloperManager 页面的代码
@model IEnumerable<ReviewSite.Models.Developer>
@{
ViewBag.Title = "Index";
}
<h2>Developers</h2>
<p>
@Html.ActionLink("Games","Index","GameManager")
@Html.ActionLink("Developers","Index","DeveloperManager")
@Html.ActionLink("Publishers","Index","PublisherManager")
@Html.ActionLink("Genres","Index","GenreManager")
</p>
<button id="createLink">Create New</button>
<table>
<tr>
<th>
Developer Name
</th>
<th>
Developer URL
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
<span class = "DeveloperName" >@Html.DisplayFor(modelItem => item.DeveloperName)</span>
</td>
<td>
<span class = "DeveloperURL" >@Html.DisplayFor(modelItem => item.DeveloperURL)</span>
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.DeveloperID }, new { id = "editLink" }) |
@Html.ActionLink("Details", "Details", new { id=item.DeveloperID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.DeveloperID}, new { @class = "deleteLink"})
</td>
</tr>
}
</table>
<script type="text/javascript">
$(document).ready(function () {
var $createDialog = $('<div></div>')
.load('/DeveloperManager/Create')
.dialog({
autoOpen: false,
title: 'Create Developer',
modal: true
});
$('#createLink').click(function() {
$createDialog.dialog('open');
return false;
});
});
</script>
当我单击删除时,它将此页面称为对话框
@model ReviewSite.Models.Developer
@{
ViewBag.Title = "Delete";
}
<h2>Delete</h2>
<p>
@Html.ActionLink("Games","Index","GameManager")
@Html.ActionLink("Developers","Index","DeveloperManager")
@Html.ActionLink("Publishers","Index","PublisherManager")
@Html.ActionLink("Genres","Index","GenreManager")
</p>
<h3>Are you sure you want to delete @Model.DeveloperName?</h3>
<fieldset>
<legend>Developer</legend>
<div class="display-label">Developer Name</div>
<div class="display-field">
@Html.DisplayFor(model => model.DeveloperName)
</div>
<div class="display-label">DeveloperURL</div>
<div class="display-field">
@Html.DisplayFor(model => model.DeveloperURL)
</div>
</fieldset>
@using (Html.BeginForm()) {
<p>
<input type="submit" value="Delete" /> |
@Html.ActionLink("Back to List", "Index")
</p>
}