Search code examples
jqueryajaxasp.net-mvc-4

jQuery.load() not executed with Ajax.ActionLink


I'm trying to develop Tabs functionality by links in MVC project with below code -

@{
    var ajaxOptions = new AjaxOptions
                          {
                              HttpMethod = "POST",
                              InsertionMode = InsertionMode.Replace,
                              UpdateTargetId = "contentPanel",                                   
                              OnComplete = "EnhanceGui",
                              OnFailure = "HandleError"
                          };
}

// This generates link and clicking it load other partial view
@Ajax.ActionLink("Users", "Users", "Admin", ajaxOptions)

Problem - How to make jQuery load() events to be executed when user click on link?

I am aware about Ajax working that it doesn't load script and only update specific area. But is there no other way for making it possible?


Solution

  • Since @Ajax.ActionLink replaces content of UpdateTargetId, I planned to put my scripts (jquery and custom scripts) in each partial view as follow -

    @model System.Collections.IEnumerable
    
    <div class="block-title">
    <h2 class="h2Users">Users</h2>
    </div>
    <div class="block-body">    
    <div class="padTop10">
        @Html.Partial("_GridViewPartial", Model)
    </div>
    @Scripts.Render("~/bundles/prAdmin") // SCRIPTS WILL BE ADDED IN MAIN PAGE
    </div>
    

    Now all scripts are available for each partial view, all functionality depending on script works smoothly.