Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8576139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:51:31+00:00 2026-06-11T19:51:31+00:00

I have a view that has some jQuery to load a partial view (via

  • 0

I have a view that has some jQuery to load a partial view (via a button click) into a div in the view. This works without a problem. However within the partial view I have a very similar bit of jQuery that will load another partial view into a div in the first partial view, but this isn’t working, it almost seems like the jQuery in the first partial view isn’t being loaded.

I have tried searching for solutions, but I haven’t managed to find an answer. I have also re-created the jQuery function in a @Ajax.ActionLink which works fine, however I am trying to avoid the Microsoft helpers as I am trying to learn jQuery.

Here is the first partial view which contains the jQuery that doesn’t seem to work, it also contains the @Ajax.ActionLink that does work:

@model MyProject.ViewModels.AddressIndexViewModel

<script>
    $(".viewContacts").click(function () {
        $.ajax({
            url: '@Url.Action("CustomerAddressContacts", "Customer")',
            type: 'POST',
            data: { addressID: $(this).attr('data-addressid') },
            cache: false,
            success: function (result) {
                $("#customerAddressContactsPartial-" + $(this).attr('data-addressid'))
                        .html(result);
            },
            error: function () {
                alert("error");
            }
        });
        return false;
    });
</script>
<table class="customers" style="width: 100%">
    <tr>
        <th style="width: 25%">
            Name
        </th>
        <th style="width: 25%">
            Actions
        </th>
    </tr>
</table>
    @foreach (Address item in Model.Addresses)
    {
    <table style="width: 100%; border-top: none">
        <tr id="address-id-@item.AddressID">
            <td style="width: 25%; border-top: none">
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td style="width: 25%; border-top: none">
                <a href="#" class="viewContacts standardbutton" data-addressid="@item.AddressID">ContactsJQ</a>
                @Ajax.ActionLink("Contacts", "CustomerAddressContacts", "Customer",
                    new { addressID = item.AddressID },
                    new AjaxOptions { UpdateTargetId = "customerAddressContactsPartial-" + @item.AddressID, HttpMethod = "POST" },
                    new { @class = "standardbutton"})
            </td>
        </tr>
    </table>
    <div id="customerAddressContactsPartial-@item.AddressID"></div>
    }

If someone could explain what I am doing wrong here and how to fix it then I would be very grateful.

Thanks very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:51:32+00:00Added an answer on June 11, 2026 at 7:51 pm

    I have also re-created the jQuery function in a @Ajax.ActionLink
    which works fine, however I am trying to avoid the Microsoft helpers
    as I am trying to learn jQuery.

    In case you didn’t know, in ASP.NET MVC 3, Ajax.* helper use jQuery, contrary to ASP.NET MVC 2 where they were using Microsoft Ajax scripts. Also it is considered bad practice to put javascript code in your views and partial views.

    I would recommend you externalizing this in a separate javascript file inside a function.

    function ajaxifyViewContactsLink() {
        $('.viewContacts').click(function () {
            $.ajax({
                url: this.href,
                type: 'GET',
                cache: false,
                context: this,
                success: function (result) {
                    // see the updated markup of the partial below
                    // that works with this:
                    $(this).closest('.address')
                           .find('.results')
                           .html(result);
                },
                error: function () {
                    alert("error");
                }
            });
            return false;
        });
    }
    

    You haven’t shown how you rendered this partial, I guess you used AJAX again, so in the success callback of this AJAX call once you inject the partial into the DOM you invoke the ajaxifyViewContactsLink function.

    Now your partial simply contains what it should contain – markup:

    @model MyProject.ViewModels.AddressIndexViewModel
    <table class="customers" style="width: 100%">
        <tr>
            <th style="width: 25%">
                Name
            </th>
            <th style="width: 25%">
                Actions
            </th>
        </tr>
    </table>
    @foreach (Address item in Model.Addresses)
    {
        <div class="address">
            <table style="width: 100%; border-top: none">
                <tr id="address-id-@item.AddressID">
                    <td style="width: 25%; border-top: none">
                        @Html.DisplayFor(modelItem => item.Name)
                    </td>
                    <td style="width: 25%; border-top: none">
                        @Html.ActionLink(
                            "ContactsJQ", 
                            "CustomerAddressContacts", 
                            "Customer",
                            new { addressid = item.AddressID },
                            new { @class = "viewContacts" }
                        )
                    </td>
                </tr>
            </table>
            <div class="results"></div>
        </div>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this page that has some basic custom tabs: http://demo.unlockedmanagement.com/users/view/2 * NOTE
Scenario: I have a view that has some DataTemplate resources <DataTemplate x:Key=myDragCueTemplate> <Border Background=Blue
I'm using MVC2 with VS2010 I have a view that has two partial views
I am using jQuery.load() to render a partial view. This part looks like this:
I have a page that has some content and 3 partial views each holding
I have a view that has a column to make it sortable. When clicking
I have a view that has a tooltip attribute. I want to set that
I have a view that has multiple views inside it, and an image presentation
In my app I have a view that is a form that has quite
I have a view MainView that has a navigation bar without any navigation controller,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.