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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:06:10+00:00 2026-05-12T17:06:10+00:00

I have an ASP.NET MVC app with a form. Say this form has an

  • 0

I have an ASP.NET MVC app with a form. Say this form has an arbitrary number of buttons, each with their own action.

<input type="button" id="action1" value="One" />
<input type="button" id="action2" value="Two" />
... and so forth

We want the user to click on one and have a jQuery action fire to submit the form and then repost the form with new information.

There are several ways to implement this. What is the best practice on how to design this elegantly? Please provide code snippets if you can.

  • 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-12T17:06:10+00:00Added an answer on May 12, 2026 at 5:06 pm

    Set up an object literal of potential actions:

    var actions = {
      action1: function(elem) {
        // If you just want to submit the form normally
        $(elem).closest('form').submit();
        ...
      },
      action2: function(elem) {
        // If you wanted to ajax load a url-field into a div
        var url = $('#url_field').val();
        $('.display').load(url);
        ...
      }
    }
    

    Then write a selector that grabs all the buttons (be as specific as you need to be) and attach each function based on the element’s id to the click handler. Using event delegation (‘$.live()’) you can increase performance for the case when there are several buttons, or when buttons are added dynamically.

    $('input[type=button]').live('click', function(e){
      actions[$(this).attr('id')](this);
    });
    

    This would call the related action in the ‘actions’ variable on each click (you should probably validate that the function exists, as well).

    Then inside each of the action functions, you can submit to different urls, or ajax submit, or load new information, or do anything you want. As far as ‘repost[ing] the form’ goes, that would be a server-side function that prefilled each input element with its previous value, much like you would do on an invalid submit.

    This gives you a single line of code to handle the events, and then a clean structure to build each of your actions in.

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

Sidebar

Related Questions

i have an asp.net mvc app that has a form that uploads a file.
I have an ASP.NET MVC app and I want to add to each page
I have an ASP.NET MVC 3 app hosted on IIS. This app is using
I'm building an advanced search form for my ASP.NET MVC app. I have a
I'm working on an ASP.NET MVC app (using MVC3 RC2). Say I have 2
In my ASP.NET MVC 3 app I have a page where, after its form
say for instance I have the following button in a form in asp.net mvc
I'm developing a web app with asp.net mvc 3 and I have some form
I have a very basic email submission form in my ASP.NET MVC 3 app.
I have an ASP.Net-MVC app using LinqToSql. I have a subcontracts table, a service_lines

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.