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 8812569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:38:03+00:00 2026-06-14T03:38:03+00:00

I have a MVC page that loads a Partial via a Ajax.ActionLink, which works,

  • 0

I have a MVC page that loads a Partial via a Ajax.ActionLink, which works, and then the loaded Partial contains a form that has Ajax.BeginForm. This form is not getting wired up to unobtrusive ajax, and instead is performing a page refresh(I verified this in the Network log of the browser that shows the initiator when I click submit is the browser instead of jquery).

What I believe is the issue is that since the form didn’t exist when the page is loaded(but later is added via the Ajax.ActionLink), then unobtrusive ajax didn’t see the data-ajax attributes on the newly added form and wire up the necessary events. I’m assuming that only happens at document.ready, and the ajax form didn’t exist then.

Is there something I can do to say “hey Unobstrusive Ajax, please look at my page again now that I have some new elements that are marked with data-ajax and wire them up”?

Thanks.

Looking at the unobtrusive ajax source, it has this:

$("form[data-ajax=true]").live("submit", function (evt) {
        var clickInfo = $(this).data(data_click) || [];
        evt.preventDefault();
...

The form tag generated looks like this:

<form action="/Path/Create" class="form-horizontal" data-ajax="true" data-ajax-method="post" data-ajax-mode="replace" data-ajax-update="#ParentContainer" id="PathForm" method="post" novalidate="novalidate">

As far as I can tell the selector on the .live event should be picking up on the new form when it’s loaded onto the page. The form is inside a bootstrap modal however, so I don’t know if that would be preventing the event from bubbling up somehow.

I can even run this in Chrome console:

 $("form[data-ajax=true]").live("submit", function (evt) {
            var clickInfo = $(this).data(data_click) || [];
            evt.preventDefault(); });

And it returns the form element successfully, but when I click submit it still does a full page refresh. I would expect it to at least do nothign since I wired it up to preventDefault.

  • 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-14T03:38:04+00:00Added an answer on June 14, 2026 at 3:38 am

    To answer my own question regarding unobtrusive ajax and dynamically loaded content, it should work fine out of the box. The way it wires up to events with .live(deprecated, still works currently) should detect forms that are loaded dynamically onto the page. So apparently it doesn’t suffer the same problem that unobtrusive validation does.

    Our problem was unrelated to that. We were using bootstrap modal which spawned a modal div from inside a form. Since the modal then loaded another page containing a form, we realized we had a form within a form (even though it didn’t really look that way since the other form was in a modal).

    To solve this we moved the declaration of the modal div in the first form outside of the form. We could still have a link that referenced the modal to show it, but not the modal’s inner form wouldn’t be nested in the first form.

    I believe the reason this caused both the .live and .on methods to not catch the event was because they depend on the event to bubble up to the document, and it bubbled up only as far as the outer form which was not an ajax form, thus did not match the selector.

    Another solution would have been to write .on more like this so that the event would be caught when it bubbled up to the container of the inner form, instead of scoping it to the document where the event would reach the outer form first.

    $('#innerModalId').on("submit", "form[data-ajax=true]", function (evt) {
       evt.preventDefault(); 
       ...
       return false 
    });
    

    However since this was part of a library, that’s not an ideal solution as I would have needed to repeat their code. We didn’t get as far as updating unobtrusive ajax:
    http://nuget.org/packages/jQuery.Ajax.Unobtrusive

    But I think we would have still had the problem since even with .on it still didn’t work due to our page structure problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page which contains a html.RenderPartial, that renders an ASP.NET MVC partial
I'm using ASP.NET MVC 2 and have a login page that is secured via
I have a search page on my MVC site that contains a list of
In a page that has a grid/list dynamically loaded via AJAX, an efficient way
i have a page that loads a bunch of different windows which each come
I have my own MVC and autoloader that loads classes. Everything works except that
I have a MVC page which allows creation and editing of a subcontract. When
I have an MVC page, with some controls inside a form. The part I
I have a ASP.NET MVC page, which call WCF logic. The system is single-signon
I have an ASP.Net-MVC application that is mostly complete. However, I have one page

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.