1

I am using MVC3 with Jquery's .load() with a PartialView().

From my jquery, I am doing the following:

      $("#stlist").load('@Url.Action("KitEdit","Kit")' + '?id=' + id+ '&pick=' + pick)

The partial view is called from the KitEdit action.

I was wondering if there is another way of loading a partial view besides the .load()?

I am getting some wierd behaviors where once the .load is done, some of the buttons don't work the second time.

1
  • "Some of the buttons don't work the second time" I think we need more information to assist you. Are you loading javascript with the partial view? can you provide a simple example of the issues you are having? Commented Jul 5, 2012 at 19:27

2 Answers 2

2

Is the partial view displayed without refreshing the entire page? If so, you need to add some jQuery that will run after the partial view is loaded to hook up all of the controls in the partial view. What I would suggest is adding a complete function (http://api.jquery.com/load/) to your jQuery .load() call like this:

 $("#stlist").load('@Url.Action("KitEdit","Kit")' + '?id=' + id+ '&pick=' + pick, Complete);

Then the complete function would hook up all the controls from the partial view.

Hope this helps!

Sign up to request clarification or add additional context in comments.

4 Comments

Hi nikeaa,Complete doesn't seem to work. Meaning, it doesn't work at all if I put in Complete. Am I doing something wrong?
Did you define the Complete() function in your JS on the main view page?
I could not find an example of the Complete() function in the link you mentioned. Might you have one that I can look at?
Actually, a little better would be to do the following: $("#stlist").load('@Url.Action("KitEdit","Kit")' + '?id=' + id+ '&pick=' + pick, function() { //put your code here }); This will define the function right in your .load call. Within the function $(this) will refer to the element found by the "#stlist" selector.
1

If your buttons are using jquery click events you may to modify them to use .on syntax when defining the click behavior.

1 Comment

live method is deprecated on method should be used instead

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.