1

i'm building a view for editing a variable length list using this http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/ solution.
Here's my ActionLink:

 <%= Html.ActionLink("Add another...", "AddReceiver", null, new { id = "addItem" })%>

And here's my javascript code:

$("#addItem").click(function () {
$.ajax({
    url: this.href,
    cache: false,
    success: function (html) { $("#editorRows").append(html); }
});
return false;});

The problem is that click event is not fired, so i'm getting not the ajaxly updated view, but an empty page with my partial view, gotten from the AddReceiver action.
Any suggestions, guys?

4

2 回答 2

2

听起来您的浏览器在执行该click函数后立即跟踪该链接,从而覆盖了您的脚本。尝试使用事件的preventDefault()方法。

$("#addItem").click(function (event) {
  event.preventDefault();
  $.ajax({
    url: this.href,
    cache: false,
    success: function (html) { $("#editorRows").append(html); }
  });
  return false;
});
于 2011-04-22T11:39:41.813 回答
0

$(document).ready (...) 函数中是否定义了点击处理函数?

于 2011-04-22T11:49:51.477 回答