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

  • Home
  • SEARCH
  • 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 8219715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:16:24+00:00 2026-06-07T13:16:24+00:00

I think I’m missing something simple, but I’m blinded by looking at the same

  • 0

I think I’m missing something simple, but I’m blinded by looking at the same code over and over and could use another set of eyes.

I have an MVC partial view that contains a Form.

<div class="Clear"></div>
 <div class="OverFlow">
     @using (Html.BeginForm(null, null, FormMethod.Post, new {id = "formId"}))
     {
         <div class="ErrorBx1">@Html.GetData()</div>
         <table>
             @Html.EditorFor(m => m.FormModel, "MyEditorTemplate") 
             <tr>
                 <td colspan="2"></td>
                 <td><input type="image" src="@Images.ResolveDefault("btn-send.jpg")" alt="Send" class="Send" /></td>
             </tr>
         </table>
     }
 </div>

This view also contains some Javascript

<script type="text/javascript">
    $(function () {
        $('#formId').submit(function () {
            $.ajax({
                cache: false,
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (res) {
                    if (res.success) {
                        alert("success");
                        closeDialog();
                        window.parent.specialFunction();
                    } else {
                        alert("not success");
                        $('#someElement').replaceWith(res);
                    }
                }
            });
            return false;
        });
    });
</script>

Here is the controller method that gets executed

[HttpPost]
public ActionResult Index(MyViewModel viewModel)
{
    if (CheckSuccess())
    {
        return Json(new { success = true });
    }

    return ViewNoLayout("otherView", viewModel);
}

This View gets loaded into a jQuery.UI dialog. The first time the dialog is loaded, clicking the submit button on the form executes the success function correctly – The alert pops, the dialog is closed and the parent function is called. If I popup the dialog again and click the submit button, the call goes to the server and processes correctly, but the page reloads and only displays the JSON string (no alert, etc…). I’m assuming that there is some sort of client-side caching that I’m missing, or something equivalent. Any ideas?

  • 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-07T13:16:26+00:00Added an answer on June 7, 2026 at 1:16 pm

    Remove the document.ready from your view:

    <script type="text/javascript">
        $('#formId').submit(function () {
            $.ajax({
                cache: false,
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (res) {
                    if (res.success) {
                        alert("success");
                        closeDialog();
                        window.parent.specialFunction();
                    } else {
                        alert("not success");
                        $('#someElement').html(res);
                    }
                }
            });
            return false;
        });
    </script>
    

    The reason for that is that the document.ready is no longer executed the second time when you inject the partial into your DOM. So your submit event doesn’t get attached anymore. Be careful gotcha ahead: removing the document.ready means that you must place this script after the form in the markupor the first time you load this page it won’t attach it at all.


    Obviously all this that I am saying is only to solve your current issue.

    But your real problem is the fact that you are mixing markup and HTML. This should never be done. Markup belongs to views, script belongs to javascript files. Separate javascript files. So you should externalize this into a separate js file. So the real solution is to have the following script in a separate file using the .on() (or .delegate() if you are using legacy jQuery versions and .live() if you are using a prehistoric version of jQuery) to lively subscribe to elements that might not yet be present on your DOM at the moment of subscription:

    $(document).on('submit', '#formId', function() {
        $.ajax({
            cache: false,
            url: this.action,
            type: this.method,
            data: $(this).serialize(),
            success: function (res) {
                if (res.success) {
                    alert("success");
                    closeDialog();
                    window.parent.specialFunction();
                } else {
                    alert("not success");
                    $('#someElement').html(res);
                }
            }
        });
        return false;    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I got all the steps down but I must be missing something
I think this could be a very easy question for you. But I have
I think it will be very hard for you to read the code but
I think I'm missing something basic here. Why is the third IF condition true?
I think I'm missing something basic here. Any explanation or pointers to previously asked
I think they are same thing but my boss say that is not right.
Think my problem is I am trying to sum a count in the same
I think I have a basic understanding of this, but am hoping that someone
Think about the games like Spiral Knights and Minecraft(Which I believe both use LWJGL)
Think of this: A view controller's view is added as subview to another view.

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.