我已宣布一项行动如下:
public ActionResult EditComment(int id)
{
try
{
var comment = commentRepository.GetItem(id);
return PartialView("Comment",comment);
}
catch
{
return Content("Error!");
}
}
这就是我的观点:
.....
<%:Html.ActionLink(GlobalText.Edit,"#", null, new { @class="EditLink",id=item.CommentID})%>
.....
<div id="link">
</div>
<script type="text/javascript">
$(document).ready(function () {
$('.EditLink').click(function () {
var idval = this.id;
$.ajax({
url: "/Articles/EditComment",
data: { id: idval },
success: function (mydata) {
$("#link").empty().append(mydata);
},
type: "POST"
});
return false;
});
});
当我点击带有'EditLink'类的链接时,应用程序会通过运行操作结果,但是'$(“#link”)。empty()。append(mydata);' jquery不起作用,我什么都没得到!
答案 0 :(得分:0)
尝试更改public ActionResult - to PartialResult EditComment(int id)
$(document).ready(function () {
$(".EditLink").each(function(){
$(this).click(function () {
var idval = this.id;
$.ajax({
url: "/Articles/EditComment",
data: { id: idval },
success: function (mydata) {
$("#link").empty().append(mydata);
},
type: "POST"
})
});
}