首先,抱歉我的英语不好。 我不明白为什么当我点击删除用户时我的页面不刷新... 点击后我签入数据库并且用户被删除但我的页面没有刷新表,我不明白。
我的观点是:
@model IEnumerable<SiteWebEmpty.Models.User.UserDisplay>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.debug.js")" type="text/javascript"></script>
<h2>Display User</h2>
<div id="deleteUser">
@using (Html.BeginForm())
{
<table class="tabledisplayUser" border="1">
<tr>
<th>Name FirstName</th>
<th>UserName</th>
<th>Roles</th>
<th>Choice</th>
</tr>
<tr>
<th>@Html.Editor("name")</th>
<th>@Html.Editor("username")</th>
<th>@Html.Editor("roles")</th>
<th>@Html.Editor("choice")</th>
</tr>
@foreach (var user in Model)
{
<tr>
<td class="action nameFirstName">@Html.DisplayFor(u => user.NameFirstName)</td>
<td class="action userName">@Html.DisplayFor(u => user.UserName)</td>
@if (user.Roles.Roles.Count.Equals(0))
{
<td>Nobody Role</td>
}
else
{
<td>@Html.DropDownList("Roles", user.Roles.Roles)</td>
}
<td>@Html.ActionLink("Edit", "Edit", new { UserName = user.UserName }) | @Ajax.ActionLink("Delete", "Delete", new { UserName = user.UserName },
new AjaxOptions()
{
HttpMethod = "POST",
Confirm = "Do you want delete this user?",
UpdateTargetId = "deleteUser"
})</td>
</tr>
}
</table>
}
</div>
我的控制器是:
public ActionResult DisplayUser()
{
List<UserDisplay> users=getAllUserInDB();
GetAllNameFirstNameLDAP(users);
return View(users);
}
public ActionResult Delete(String userName)
{
DeleteDB(userName);
if (!Request.IsAjaxRequest())
return RedirectToAction("DisplayUser");
else
{
List<UserDisplay> users = getAllUserInDB();
GetAllNameFirstNameLDAP(users);
return PartialView("DisplayUser",users);
}
}
我不明白为什么它不起作用,谢谢你的帮助!
答案 0 :(得分:1)
UpdateTargetId = "deleteUser"
表示使用id="deleteUser"
刷新DOM元素。你没有这样的元素。
你有:
<div class="deleteUser">
与以下内容不同:
<div id="deleteUser">
所以用id替换类,你的表应该正常刷新。