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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:16:03+00:00 2026-06-16T06:16:03+00:00

I am developing an MVC4 mobile app that uses several forms which are loaded

  • 0

I am developing an MVC4 mobile app that uses several forms which are loaded into a section on the layout via ajax. I’ve got jQuery mobile set with Ajax turned off so I can manage the Ajax myself. Most of the forms work fine, the load and submit via ajax as they should. However, so far there is one form that refuses to fire the form submit and submit the form via ajax like the rest. First, the form is loaded when a user clicks to add a contact and this works fine:

// Handle the add contact button click
$('#btnAddNewContact').on('click', function (e) {
    e.preventDefault();
    // Make sure a location was selected first.
    var locationID = $('#cboLocation').val();
    if (locationID.length === 0) {
        //$('#alertTitle').text('REQUIRED');
        $('#alertMsg').html("<p>A Contact must be associated with a Location.</p><p>Please select or add a Location first.</p>");
        $('#alertDialogDisplay').click();            
    } else {
        SaveOpportunityFormState();
        $.cookie('cmdLocationId', locationID, { path: '/' });
        $.mobile.loading('show');
        $.ajax({
            url: '/Contact/Add',
            type: 'GET',
            cache: false,
            success: function (response, status, XMLHttpRequest) {
                $('section.ui-content-Override').html(response);
                // Refresh the page to apply jQuery Mobile styles.
                $('section.ui-content-Override').trigger('create');
                // Force client side validation.
                $.validator.unobtrusive.parse($('section.ui-content-Override'));
            },
            complete: function () {
                $.cookie('cmdPreviousPage', '/Opportunity/Add', { path: '/' });                    
                AddContactLoad();
                ShowSearchHeader(false);
                $.mobile.loading('hide');
            },
            error: function (xhr, status, error) {
                // TODO - See if we need to handle errors here.
            }
        });
    }
    return false;
});

Notice that after successfully loading the form the AddContactLoad() function is fired. This works fine and here is that code:

function AddContactLoad() {
$('#contactVM_Phone').mask('(999) 999-9999? x99999');                
$('#frmAddContact').on('submit', function (e) {
    e.preventDefault();
    if ($(this).valid()) {
        $.mobile.loading('show');
        $.ajax({
            url: '/Contact/Add',
            type: 'POST',
            cache: false,
            data: $(this).serialize(),
            success: function (response, status, XMLHttpRequest) {
                if (!response) {  // Success
                    ReturnToAddOpportunity();
                } else {  // Invalid Form
                    $('section.ui-content-Override').html(response);
                    // Force jQuery Mobile to apply styles.
                    $('section.ui-content-Override').trigger('create');
                    // Force client side validation.
                    $.validator.unobtrusive.parse($('section.ui-content-Override'));
                    AddContactLoad();
                    $.mobile.loading('hide');
                }
            },
            complete: function () {

            },
            error: function (xhr, status, error) {
                // TODO - See if we need to handle errors here.
            }
        });
    }
    return false;
});
$('#btnCancel').on('click', function (e) {
    e.preventDefault();
    // See where add contact was called from.
    var previousPage = $.cookie('cmdPreviousPage');
    if (previousPage.indexOf("Detail") >= 0) {
        ReturnToOpportunityDetails();
    } else {
        ReturnToAddOpportunity();
    }
    return false;
});

}

If I click the cancel button, that code is fired so I know this is working too. Here is my form code:

@using (Html.BeginForm("Add", "Contact", FormMethod.Post, new { @id = "frmAddContact" }))
{
@Html.ValidationSummary(true)
@Html.AntiForgeryToken()    

-- Form Fields Here --

<div class="savecancel" >
    <input type="submit" value="Save" data-mini="true", data-theme="b", data-inline="true" /> 
    <a href="#" id="btnCancel" data-role="button" data-inline="true" data-theme="b" data-mini="true">Cancel</a> 
</div>   
}

As you can see the form is named frmAddContact and that is what the AddContactLoad() function is attaching the submit event to. To save my sole I cannot figure out why the form does not submit via the ajax post like every other form in the app. Am I missing some kind of initialization, I just don’t know. If anyone can please help I’d really appreciate it!!

  • 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-16T06:16:04+00:00Added an answer on June 16, 2026 at 6:16 am

    As it turns out, I had created a custom unobtrusive Ajax validator for a phone number then copied and pasted it to do the same with a zip code. Unfortunately in the process I forgot to rename a variable and thus an error was occurring in the validation script which caused the problem. In the mean time, if you’re reading this, you might take a note of the code here and how to inject HTML into a page via Ajax and jQuery mobile. I’ve never found this in a book or on the web and it contains some very useful methodology and syntax. On the form submit the reason I’m checking for the empty response is I just return null from the controller to validate the form was valid and the save worked in which case I send them to a different HTML injection i.e. that page they originally came from. If null is not returned I inject that page with the HTML containing the original form and error markup so the user can make corrections then resubmit. I’m also calling a form load method that attaches handlers to the HTML once it’s injected into the main page. Hope this helps somebody!

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

Sidebar

Related Questions

I'm developing an MVC4 mobile app using Visual Studio 2012 with jQuery Mobile. I
Developing a brand new schema/app which uses hibernate to create tables from pojo's. My
Developing an app that uses data synchronization. Sending images (even resized) takes time if
Developing a site that requires monthly subscriptions via PayPal. If a buyer has an
I am developing a JQuery mobile application in ASP.net MVC4 razor using VSRC, In
I’m aware that not everyone uses a thorough architecture when developing an MVC application
Developing a web app which should enable users to organize the events on their
I'm developing an app in ASP.Net MVC4 and am having a strange issue with
I am at present developing a mvc4 project that comunicates to a set of
I've got an mvc4 app I've been developing, and I'm getting ready to deploy

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.