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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:36:55+00:00 2026-06-08T23:36:55+00:00

I have the following code and when I click the submit button its name

  • 0

I have the following code and when I click the submit button its name and value isn’t being sent to the server

@using(Ajax.BeginForm(new AjaxOptions{Url = "http://localhost/controller/action"}))
{
    <button name="action" type="submit" value="Save">
        <span>Save</span>
        <!-- More HTML tags here -->
    </button>
}

I had a look in the jquery.unobtrusive-ajax.js file to see if it should send the name/value of the button that was clicked and found this code that attaches these values as an attribute to the form which is later passed along in the post request.

$("form[data-ajax=true] :submit").live("click", function (evt) {
    var name = evt.target.name,
        form = $(evt.target).parents("form")[0];

    $(form).data(data_click, name ? [{ name: name, value: evt.target.value }] : []);

    setTimeout(function () {
        $(form).removeData(data_click);
    }, 0);
});

The values of evt.target.name and evt.target.value contained the name/value from the HTML element within the button tag that registered the click.

I managed to get it to work by replacing evt.target with evt.currentTarget in the above code but I’m a bit worried this may have unintended side effects.

Is there a better way to send the submit button’s name/value to the server?

  • 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-08T23:36:57+00:00Added an answer on June 8, 2026 at 11:36 pm

    I’ve reproduced the problem you describe and your proposed code fix seems to do the trick for me.

    I can understand your reluctance in modifying the standard jquery.unobtrusive-ajax.js library since you’ll have to remember to merge your changes when a new version is released. A better option would be to submit a patch so your fix can be reviewed and hopefully incorporated into the standard library. I don’t know the best way of going about this but I believe that a large proportion of ASP.NET code is now open source, including MVC, and that Microsoft have begun to accept code contributions from the community. I would suggest having a look at http://aspnetwebstack.codeplex.com/ for more info.

    As an alternative to changing the library, have you considered eliminating the need to include child elements inside your button? If your button only contains text (and no tags) the standard library works correctly and posts the button’s name and value. If you need images you may be able to get away with using the CSS background-image property instead of a nested img tag.

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

Sidebar

Related Questions

I have the following submit button: <form id=form1 runat=server> <input type=submit id=submit value=Submit runat=server/>
I have the following code bound to the click event of a button: function
I have the following code that responds to a button click, changes the view
I have the following code that works on Firefox and Chrome $("#adicionarItem").click(function(){ $.ajax({ type:
I have a form with following fields.While click on submit button I am getting
I have the following jQuery code to execute when I click a button $('#substat').click(function()
I have the following code that works great for row click, but I want
I have the following code and everytime I click on one of the markers,
I have the following code $(document).ready(function() { $('a#slick-toggle').click(function() { $('#slickbox0').toggle(400); return false; }); });
I have the following code: visitSite.hidden = YES; For some reason, when I click

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.