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?

2 Answers 2

2

It sounds like your browser is following the link immediately after executing the click function and thus overriding your script. Try using the preventDefault() method of the event.

$("#addItem").click(function (event) {
  event.preventDefault();
  $.ajax({
    url: this.href,
    cache: false,
    success: function (html) { $("#editorRows").append(html); }
  });
  return false;
});
Sign up to request clarification or add additional context in comments.

Comments

0

Is the click handler function defined in the $(document).ready (...) Function?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.