0

I have been searching around the web and reading articles for nearly a week on this topic, but I apologize if it has already been answered somewhere that I may have overlooked.

I have a (potentially) interesting case where I have an ASP.NET MVC4 (Razor) project that I have created and I would like some jQuery that is loaded and executes on my parent view to be able to manipulate objects on the partial view.

When I call my partial view like this, everything works dandy:

@{Html.RenderPartial("TicketList", "Home");}

However, I need the ability to reload this partial's data inside the parent on-demand; thus, I am using this code to call the partial:

<div id="ticketList"></div> 

<script>
    function updateTickets() {
        $.ajax({
            url: '@Url.Action("TicketList", "Home")',
            dataType: "html",
            success: function (result) {
                $("#ticketList").html(result);
            }
        });
    }

    updateTickets();
</script>

My dilemma is that with the first piece of code - the Partial renders great... All jQuery from the parent view executes as expected; however, with the second method, the jQuery will not execute. It is as if the parent jQuery doesn't recognize the new code that has been loaded via the partial.

Maybe I'm going about this the wrong way... but any help or advice would be immensely appreciated!

Many thanks :)

MadScout
  • 25
  • 6

1 Answers1

0

As I understood from your question, your partial view contains a script with function updateTickets and you call this function immediately i.e. script that updates the partial view. Its a weird approach I think. Place the function updateTickets in your parent view and call it only from your parent view. And maybe it is better to use

@Html.Partial("TicketList", "Home");

And your div should be in your parent view inside you can render your partial. You can also refer to this link

Community
  • 1
  • 1
Den
  • 360
  • 1
  • 9
  • Sorry, I should have been more clear. The two pieces of code that I referenced are two separate options that I have tried in my parent view to instantiate my partial view. Thanks for the reply! – MadScout Mar 25 '14 at 12:31