4

When i use

 $("#FormEthernet").submit();

Form is posted, action is hit in my controller, but there is no data passed, all inputs are null.

(The parameters dictionary contains a null entry...)

Here is my form

 @using (Html.BeginForm("MyAction", "MyController",FormMethod.Post, new { id = "FormEthernet",name="FormEthernet" }))
{
  <div id="dialog-formEthernet" title="Update Ethernet Config">
    <p class="validateTips">
        All form fields are required.</p>
    <fieldset>
        <div>
            Phone Number</div>
        <div>
            <input type="text" name="TNEthernet" id="TNEthernet" />
        </div>
        <div>
            Up</div>
        <div>
            <input type="text" name="Up" id="Up" /></div>
        <div>
            Down</div>
        <div>
            <input type="text" name="Down" id="Down" /></div>
    </fieldset>
  </div>
}

Any ideas? JQUERY Bug?

update here is my controller

    [HttpPost]
    public ActionResult MyAction(string TNEthernet,string Up, string Down)
    {
        return RedirectToAction("MyOtherAction", new { id = TNEthernet });
    }

And Some Fiddler (Sent)

POST http://localhost:4814/MyController/MyAction HTTP/1.1
Host: localhost:4814
Connection: keep-alive
Content-Length: 0
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Origin: http://localhost:4814
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Referer: http://localhost:4814/MyController/MyOtherAction/11255
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Cookie: .ASPXAUTH=C20491A7FB3B40E5761.......E2EE4291A5D

Here is what calls my submit:

$("#dialog-formEthernet").dialog({
            autoOpen: false,
            height: 300,
            width: 350,
            modal: true,
            buttons: {
                "Set Configuration": function () {
                    var bValid = true;
                    allFields.removeClass("ui-state-error");
                    bValid = bValid && ensureTN(TNEthernet);
                    //up and down

                    bValid = bValid && checkRegexp(UP, /^\d+$/, "Upload");
                    bValid = bValid && checkRegexp(DOWN, /^\d+$/, "Download");
                    if (bValid) {
                        alert($("#Up").val()); //this works

                        $("#FormEthernet").submit();


                    }
                },
                Cancel: function () {
                    $(this).dialog("close");
                }
            },
            close: function () {
                allFields.val("").removeClass("ui-state-error");
            }
        });

My HTML source

<form action="/MyController/MyAction" id="FormEthernet" method="post" name="FormEthernet"><div id="dialog-formEthernet" title="Update Ethernet Config">
    <p class="validateTips">
        All form fields are required.</p>
    <fieldset>
        <div>
            Phone Number</div>
        <div>
            <input type="text" name="TNEthernet" id="TNEthernet" />
        </div>
        <div>
            Up</div>
        <div>
            <input type="text" name="Up" id="Up" /></div>
        <div>
            Down</div>
        <div>
            <input type="text" name="Down" id="Down" /></div>
            <input id="FOO" name="FOO" type="text" value="FOO!" />

           <input type="submit" />
    </fieldset>
</div>
</form>
0

1 Answer 1

6

added this right before .submit()

 $("#dialog-formEthernet").parent().appendTo($("#FormEthernet"));

and solved!

See here:

jQuery UI Dialog with ASP.NET button postback

To quote "Chad Rupper" : Primarily its because jquery moves the dialog outside of the Form tags using the DOM. Move it back inside the form tags and it should work fine. You can see this by inspecting the element in Firefox.

The code: Robert MacLean

Forgive me for shaking you all up a bit!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.