0
首先,對不起我的英語不好。 我不明白爲什麼我的網頁不刷新,當我點擊刪除用戶... 點擊後,我檢查數據庫和用戶是刪除,但我的網頁表不刷新,我不明白。爲什麼ajax.actionlink不刷新頁面?
我的看法是:
@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);
}
}
我不明白爲什麼它不工作,感謝你的幫助!
這是工作!謝謝你的幫助 – Zoners 2012-03-08 15:59:25