我正在努力了解Ajax是如何工作的。我想使用Ajax.ActionLink更新一个,但我不管它工作,请帮忙...
其他所有内容都适用于此代码(我删除了评论......)。
以下是代码:
<div id="test">
<% foreach (var comment in Model.Comments)
{ %>
<p>
<b>
<%: comment.Time %>
-
<%: comment.Name %>
</b>
<%: Html.ActionLink("Redigera", "CommentEdit", new { id = comment.CommentsID }, new { @class = "ico-edit-comment" })%>
<%: Ajax.ActionLink("Ta bort", "CommentDelete", "Admin", new { id = comment.CommentsID}, new AjaxOptions { Confirm = "Ta bort kommentar?", UpdateTargetId = "test" })%>
</p>
<p>
<%: comment.Message %>
</p>
<% } %>
</div>
我的控制器看起来像这样:
//
// Ajax: /Admin/CommentDelete/5
public ActionResult CommentDelete(int id)
{
var commenttodelete = adminCommentRepository.GetComment(id);
var selectednews = adminNewsRepository.GetArticle(commenttodelete.NewsID);
adminCommentRepository.Delete(commenttodelete);
adminCommentRepository.Save();
return View("ArticleDetails", selectednews);
}
我有这三个文件的链接:
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="../../Scripts/jquery/js/jquery-1.4.2.min.js" type="text/javascript"></script>