2

This code was working at one point. I'm not sure what broke it, but basically on postback I'm looking for the existence of a submit button key in the FormsCollection. Depending on the existence, I perform different operations. The custom attribute to handle this is getting hit. When I step through it and look at the FormsCollection, I can see all key/values from the form except for the submit button which submitted the form.

Looking at the submission via Fiddler2, it doesn't even look like the submit button is being sent to the server with the rest of the values. If I put in a hidden field with the same name I am looking for (and hard coded value) I can successfully hit the "if exists" logic branch because the hidden field's value is sent to the server.

Here's my form:

@using (Html.BeginForm("Respond", "AccountInvitations", new {id = Model.Invitation.InvitationCode, ReturnUrl = Request.QueryString["ReturnUrl"] ?? string.Empty}, FormMethod.Post, new {@class = "invitation-details-form"}))
{
<div class="modal-body">
    <div class="status-message info">
        <i></i>
        You have been invited to join <strong>@Model.Invitation.AccountName</strong>.
        Create your profile below to join this account.
    </div>

    @Html.AntiForgeryToken()
    @Html.ServerValidationSummary()
    @Html.EditorFor(model => model.InvitationResponse, "InvitationResponseDto", "")

</div>

<div class="modal-footer">
    <div class="button-container clearfix">
        <input type="submit" name="accept" value="Accept Invitation" class="btn btn-secondary" />
        <input type="submit" name="decline" value="Decline Invitation" class="btn btn-link cancel" />
    </div>
</div>
}

Neither "accept" nor "decline" shows up in the FormsCollection when I press on either (the form is submitted and all fields from the editor template show, but not the submit inputs).

I do not want to handle this with javascript setting a hidden field value.

HansUp
  • 95,961
  • 11
  • 77
  • 135
MikeAtCodeSmart
  • 591
  • 7
  • 14
  • see here how to handle multiple submit buttons: http://stackoverflow.com/questions/442704/how-do-you-handle-multiple-submit-buttons-in-asp-net-mvc-framework – sjkm Nov 20 '13 at 23:40
  • This is not a duplicate. I've already implemented something similar to handle multiple submit buttons. As I've noted in the question, the submit input buttons weren't being submitted with the post. I answered my question below however I cannot accept it for another 23 hours. – MikeAtCodeSmart Nov 22 '13 at 00:21

2 Answers2

3

Wow, it's been a long couple nights coding. This post led me to the answer. A couple weeks back a script was added to prevent double clicking on some form entries. The form disabled the inputs immediately upon form submission. A simple setTimeout() to delay the disabling did the trick.

Community
  • 1
  • 1
MikeAtCodeSmart
  • 591
  • 7
  • 14
0

OR you can using

<div class="modal-footer">
    <div class="button-container clearfix">
        @using (Html.BeginForm("Your_ActionResult", "Your_controller"}, FormMethod.Get/Post))
        {
            @Html.AntiForgeryToken()
            <input type="submit" name="accept" value="Accept Invitation" class="btn btn-secondary" />
        }
        @using (Html.BeginForm("Your_ActionResult", "Your_controller"}, FormMethod.Get/Post))
        {
            @Html.AntiForgeryToken()
            <input type="submit" name="decline" value="Decline Invitation" class="btn btn-link cancel" />
        }
    </div>
</div>

you must specify the submit button that call the ActionResul method in your Controller is

TienKenji
  • 63
  • 2
  • 5
  • 17
  • So it won't pass the value if more than one submit input is within the form? Unfortunately the way the html is laid out I can't really set it up that way. You moved the form into the footer, when if you notice in my OP the body contains an Editor view which contains several input elements that are required. – MikeAtCodeSmart Nov 21 '13 at 04:25
  • I've tried removing one of the submits and posted the form with only one in there however the one submit there is not being passed in either. – MikeAtCodeSmart Nov 21 '13 at 04:29
  • @Mike You can use FormCollection in Controller and get the key/value. In your case, your controller will be like: http://dotnetfiddle.net/1tQ6TX and the html like: http://dotnetfiddle.net/ORx5e8 . Sorry to post the link, I don't see answer section below. – ACS Nov 25 '13 at 19:53