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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:46:31+00:00 2026-05-11T16:46:31+00:00

If you are using Ajax.BeginForm() with multiple submit buttons similar to this: // View.aspx

  • 0

If you are using Ajax.BeginForm() with multiple submit buttons similar to this:

// View.aspx
<% using (Ajax.BeginForm("Action", "Controller", 
           new AjaxOptions { UpdateTargetId = "MyControl",  }))
{ %>
    <span id="MyControl">
       <% Html.RenderPartial("MyControl"); %>
    </span>
<% } %>

//MyControl.ascx
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<input name="prev" type="submit" value="prev" />
<input name="next" type="submit" value="next" />
//...

Everything is submitted to the controller fine but the params for the submit button that was clicked are absent from the Request. In otherwords Request[“next”] and Request[“prev”] are always null.

I looked in to the JavaScript in Microsoft.MvcAjax.js and it looks like the function Sys_Mvc_MvcHelpers$_serializeForm completely skips over the inputs that are of type ‘submit’.

This doesn’t seem logical at all. How else can you find out what button has been clicked?

It looks like a bug to me. Is there any logical reason to skip these form parameters?

  • 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-11T16:46:32+00:00Added an answer on May 11, 2026 at 4:46 pm

    UPDATE: 2009-11-21
    I downloaded MVC Release 2 Preview 2 and looked to see if this problem was fixed.
    I did a quick test and found similar results to MVC Release 2 Preview 1.
    I don’t believe it is fixed yet.

    UPDATE: 2009-08-07
    I downloaded MVC Release 2 Preview 1 and looked to see if this problem was fixed.
    I see a new function in the script MicrosoftMvcAjax.debug.js called _serializeSubmitButton and I see that when Ajax.BeginForm() renders the output there is a onclick event but when this event fires it generates an error “Microsoft JScript runtime error: ‘Sys.Mvc.AsyncForm’ is null or not an object”.

    In short it looks like a fix was attempted but it isn’t working yet or I need to do something more. The bad news is if it isn’t the later then Ajax Forms will be broken for everyone until the fix is complete.

    UPDATE: 2009-05-07
    I received feedback today from Microsoft confirming that this is a bug. They have logged the defect and said they hope to have it fixed in a future release.

    For reference I’m leaving the details of my investigation that I submitted to Microsoft. Appologies for the long post but perhaps it will be useful for anyone trying to create a work around..

    There are a couple problems in the Ajax support in MVC. To illustrate, consider the pattern illustrated in several examples on the web:

    //===========
    // View.aspx
    //===========
    <% using (Ajax.BeginForm("Action", "Controller", 
        new AjaxOptions { UpdateTargetId  = "MyControl", HttpMethod = "POST"}))
    { %>
        <span id="MyControl">
           <% Html.RenderPartial("MyControl"); %>
        </span>
    <% } %>
    
    //================
    // MyControl.ascx
    //================
    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
    <input name="startIndex" type="hidden" value="0" />
    <%= Ajax.ActionLink("Prev", "PrevAction",
        new AjaxOptions() { UpdateTargetId="MyControl", HttpMethod="POST"}) %>
    <%= Ajax.ActionLink("Next", "NextAction", 
        new AjaxOptions() { UpdateTargetId="MyControl", HttpMethod="POST"}) %>
    //...
    

    Expected:
    It is just a list that can the user can page forward and back without updating the entire page.

    Given this setup. I expect 2 links labeled “Prev” and “Next”. Clicking on “Prev” should fire the PrevAction method in the controller as a post and the value in the hidden field named “startIndex” should be available in the request parameters. I expect similar results when clicking the Next link.

    Actual:
    The reality is that the request object contains NONE of the form parameters even though it shows that it came in as a POST.

    In order to get any of the parameters using action link they must be explicitly supplied through the variation of ActionLink that includes parameters. When this is used the parameters become part of the URL of the link which defeats the purpose of having a POST.

    So why is the javascript wrong?
    I dug into the javascript code that is used to handle the submit for the example I posted with my question and I now better understand why it doesn’t handle it. The reason appears to be related to the way they have wired up events and what I believe is a shortcoming in Internet Explorer.

    The way it currently works is that the Ajax.BeginForm() helper class generates a form tag with an onsubmit() function to intercept the form submit event. When the user clicks on a submit button the onsubmit() function fires and recieves parameters, one of which is the event.

    The MicrosoftMvcAjax scripts look at the event, bundle up the form properties that are supposed to be submitted and sends the request off to the server. The problem is that per WC3 standards only the successful controls are supposed to be posted. In the case of submit buttons this is the button that was actually clicked. Under internet explorer there is no way to determine which button actually caused the submit event to fire so the script just skips all submit buttons.

    (In Firefox the event contains a property called “explictOriginalTarget” which points to the button that actually caused the event in the first place)

    Whats the fix?
    Microsoft should be fixing it. However if we need something sooner I believe the only option is to hack the MicrosoftMvcAjax scripts to wire up events differently. I have found that the form can be wired to a handle a mousedown event where the button clicked can be saved in a global variable where the onsubmit handler can insert it into the post parameters.

    Here is some code that I was testing to illustrate this technique. I have confirmed it works in both IE8 and FireFox but I haven’t tried to hack it into the MVC Ajax scripts yet… If I get more time. I may post the results here.

       <script type="text/javascript">
         var _clicked = "";
         function onSubmit(e) {
           var targ;
           if (!e) var e = window.event;
           if (e.target) targ = e.target;
           else if (e.srcElement) targ = e.srcElement;
           if (targ.nodeType == 3) //defeat Safari bug
               targ = targ.parentNode;
           alert("OnSubmit:" + _clicked + " was clicked.");
           return false;
         }
         function Click(e) {
           var targ;
           if (!e) var e = window.event;
           if (e.target) targ = e.target;
           else if (e.srcElement) targ = e.srcElement;
           if (targ.nodeType == 3) //defeat Safari bug
               targ = targ.parentNode;
           _clicked = targ.name;
           return true;
       }
    

       <form action="/Home/StandardForm" method="post" 
        onsubmit="onSubmit(event)" onmousedown="Click(event)">
          <input type="submit" name="StdPrev" value="StdPrev" />
          <input type="submit" name="StdNext" value="StdNext" />
       </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 104k
  • Answers 104k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would use a function object struct Method1 { void… May 11, 2026 at 8:36 pm
  • Editorial Team
    Editorial Team added an answer If you read carefully the documentation for IntializeCriticalSectionWithSpinCount(), it is… May 11, 2026 at 8:36 pm
  • Editorial Team
    Editorial Team added an answer The approach discussed in the post doesn't appear to do… May 11, 2026 at 8:36 pm

Related Questions

If you are using ASP.NET MVC how are you doing grid display? Rolled your
I am looking at an asp.net 2 web application that I am maintaining (but
I have a controller action that is being executed by a link that was
I have a page in my application that refreshes some content (a list of
I really love the way Ajax makes a web app perform more like a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.