user2983267
user2983267

Reputation: 13

jQuery doesn't work in partial view

I have a problem with partial view in MVC3 Razor. When I normally render partial view (with Html.RenderAction) jQuery works but when I load view, in a specific div, with ajax.actionlink jQuery for that partial view doesn't work. jQuery code is in my layout page.

Anyone knows what is the problem?

html is in partial view and script is in layout page.

when i load partial view with @{Html.RenderAction("action", "Controler"); } jquery works but when i load it with:

@Ajax.ActionLink("name", "action", "controler", new AjaxOptions
                  {

                      OnComplete = "",
                      InsertionMode = InsertionMode.Replace,
                      UpdateTargetId = "ModeliSadrzaj"
                  })

it dosent work

Upvotes: 0

Views: 928

Answers (1)

Miika L.
Miika L.

Reputation: 3353

I would need more information on what exactly is being done where, but I suspect that the following is the source of your problem.

When you use Html.RenderAction, your partial view is a part of the initial package sent to the browser. Then your javascript code (in the Layout page) is able to work on it upon document.ready event. Things work as they should.

When you use Ajax.ActionLink, your page only has an tag on it, which when clicked will load your partial view. Have you set up the code in your layout page to run only after the ActionLink has completed? If your layout page code runs on document ready, then the partial view is not there yet (since its only loaded after you click the link).

The ActionLink action does not automatically load your content, is what I am trying to say. So its not really comparable to the Html.RenderAction function.

Upvotes: 2

Related Questions