私はすでにここでいくつかの投稿を見てきましたが、私は賢明ではありません. 私は Ajax の最初の例を試しましたが、役に立ちませんでした。部分ビューは、現在のページの dom 要素を変更するのではなく、別のページに読み込まれます。
目的は、[更新] リンクをクリックすることで、現在の行のみの「最終活動日」の値を更新することです。
これを行う簡単な方法があれば教えてください。
意見:
@model IEnumerable<RegistrationManager.User>
@{
ViewBag.Title = "Users";
}
@section scripts {
@Content.Script(Url, "jquery-unobtrusive-ajax.min.js")
}
<h2>Users</h2>
<table>
<tr>
<th>Email Address</th>
<th>Given Names</th>
<th>Surname</th>
<th>Last Activity Date</th>
<th>Refresh</th>
</tr>
@foreach (var item in Model)
{
string selectedRow = "";
if (ViewBag.UserId != null && item.UserId == ViewBag.UserId)
{
selectedRow = "selectedrow";
}
<tr class="@selectedRow" valign="top">
<td>
@item.UserName
</td>
<td>
@item.Profile.GivenNames
</td>
<td>
@item.Profile.Surname
</td>
<td>
<div id="@String.Format("LastActivityDate{0}", item.UserId)">@Html.Partial("_DateOnlyPartialView", item.LastActivityDate)</div>
</td>
<td>
@Ajax.ActionLink("Refresh", "Refresh",
new { UserId = item.UserId },
new AjaxOptions {
UpdateTargetId = "LastActivityDate" + item.UserId,
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET"
})
</td>
</tr>
}
</table>
コントローラ:
public PartialViewResult Refresh(Guid? UserId)
{
User user = _db.Users.Find(UserId);
user.RefreshLastActivityDate();
return PartialView("_DateOnlyPartialView", user.LastActivityDate);
}