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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:18:53+00:00 2026-06-01T05:18:53+00:00

I have multiple ajax forms on page that cointain same elemets, I have jquery

  • 0

I have multiple ajax forms on page that cointain same elemets, I have jquery function on succes that searches childrean elements of form and updates, but I need to somehow pass Id of the form that sent request to the controller along with other values from form, what is the best way to do this? Maybe add hidden field to form and on page load get parentid and put it in this field with jQuery. But I don’t know jquery that well to do that.

@using (Ajax.BeginForm("Index", "Controller",new AjaxOptions { OnFailure = "error", OnSuccess ="sucess" }))
           {
                <input type="submit" name="value" class="up" value="1" />
                <span class="result">0</span>
                <input type="submit" name="value" class="down" value="-1" />
           }


 public ActionResult Index(int value ,string formID)
        {
           //do something
        }

function sucess(arg) {

        var json = $.parseJSON(arg.responseText);

        var form = $("form#" + json.FormID);

        var up = form.children('input.up');

        var down = form.children('input.down');

        form.children('span.result').replaceWith(json.Result);

        if (json.Result == 1) {

            up.addClass('active');

        }

        if (json.Result == -1) {

            down.addClass('active');

        }
    }

UPDATE : this is partial view that gets loaded n times so I can’t find out formID until page is rendered in browser.

  • 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-01T05:18:55+00:00Added an answer on June 1, 2026 at 5:18 am

    You could give your form an unique id and pass this id to the callback:

    @{
        var formId = Guid.NewGuid().ToString();
    }
    @using (Ajax.BeginForm("Index", "Controller", null, new AjaxOptions { OnFailure = "error", OnSuccess = string.Format("success(data, '{0}')", formId) }, new { id = formId }))
    {
        <input type="submit" name="value" class="up" value="1" />
        <span class="result">1</span>
        <input type="submit" name="value" class="down" value="-1" />
    }
    

    now inside the success function you will be able to fetch the JSON result returned by the server and the id of the form:

    function success(json, formId) {
        // Remark you don't need to call $.parseJSON here.
        // inside the success callback the first argument will already
        // represent a parsed object that you can use directly. This obviously
        // assumes that your controller action returns JSON:
        // return Json(new { Result = 1 });
    
        var form = $("#" + formId);
        var up = form.children('input.up');
        var down = form.children('input.down');
        form.children('span.result').replaceWith(json.Result);
        if (json.Result == 1) {
            up.addClass('active');
        }
        if (json.Result == -1) {
            down.addClass('inactive');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page with multiple forms that I submit via Ajax POSTs serially.
I have a form being AJAX'd in by jQuery on a page with multiple
I've got a page with multiple forms that load via ajax. Each form includes
I have a page that has multiple parts of the page loaded via ajax,
I have an app that sends multiple Ajax requests simultaneously. I was originally running
I have a html page with multiple similar elements which can be edited in-place:
I have forms located in multiple areas in my layout page (not nested). I
I have a page that contains several forms that are identical throughout a page.
I have a page which dynamically creates multiple forms, each form had a unique
I have multiple select boxes on the page all of which share the same

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.