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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:48:28+00:00 2026-05-20T09:48:28+00:00

I am using Visual Studio 2010 and MVC 3 with AJAX/JQuery. The issue I

  • 0

I am using Visual Studio 2010 and MVC 3 with AJAX/JQuery. The issue I am having is that the code is posting something twice. It only happens when you post something, then do it again.

Here is my JS:

$(document).ready(function () {
   BindEvents();
});

function BindEvents() {
$('#OpenCommentDialog').click(function (event, ui) {
    var id = $(this).attr('data');
    $('#NewCommentDialog').dialog({
        open: function (event, ui) {
            $('#BugID').val(id);
            var form = $('form', '#NewCommentDialog');
            form.submit(function (e) {
                var comment = form.serialize(true);
                CreateComment(comment);
                return false;
            });
        }
    });
    $('#NewCommentDialog').dialog('open');
    return false;
});
}

function CreateComment(comment) {
if (comment != null) {
    $.post('/Comments/Create/', comment, function (data) {
        if (data == 'Success') {
            var id = $.parseQuery(comment);
            GetComments(id.BugID);
            $('#NewCommentDialog').dialog('close');
        }
    });
}
}

function GetComments(id) {
$('#Comments').find('tr').remove();
$.getJSON('/Comments/GetComments', { id: id }, function (data) {
    if (data != null) {
        if (data.length > 0) {
            $('#CommentListTemplate').tmpl(data).appendTo('#Comments');
        }
    }
});
}

My HTML page has a JQuery dialog box that calls a CreateCommentPartial.cshtml file. When the user fills it out, it calls the “CreateComment” function, which then calls the “GetComments” and refreshes the comments after the new one is posted.

Now, here’s the issue. If you click the “Create Comment” link again, without reloading the page and fill out the form, the “CreateComment” is fired twice and “GetComments” is fired twice as well. Firebug shows me this as well.

What am I doing wrong here? If you reload the page (F5) after posting it doesn’t do this. But it defeats the purpose. One should be able to submit a comment multiple times without reloading the page.

  • 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-05-20T09:48:29+00:00Added an answer on May 20, 2026 at 9:48 am

    Where have you declared the above script? I had a similar problem with a script that was added to the page by a partial view. Somehow the script was added to the page for each click of a button thus multiplying the script and the number of posts (each copy of the script firing once). I solved the problem by putting the script in a separate .js file and referencing it in the master page

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

Sidebar

Related Questions

I have been having an issue with Visual Studio 2010 that is driving me
I'm trying to debug MVC source code in Visual Studio 2010 using the Microsoft
I'm using Visual Studio 2010 RC. Would it be possible that after doing my
I opened a solution in Visual Studio 2010 RC that I previously created using
I create a ASP.net MVC 4 project by using Visual Studio 2010 IDE. I
I am currently developing an ASP.NET MVC 3 site using Visual Studio 2010 with
I'm going to be building some ASP.Net MVC 2 software using Visual Studio 2010
Using Visual Studio 2010, MVC project When my form is submitted (currently via javascript,
Setup: I am using MVC 3, EF 4.1, Visual Studio 2010 SP1 with Power
I am using Visual Studio 2010 for an MVC website project. I have an

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.