Jquery提交不向控制器发布值

Pin*_*nch 4 c# asp.net-mvc jquery

当我使用

 $("#FormEthernet").submit();
Run Code Online (Sandbox Code Playgroud)

表单已发布,操作在我的控制器中被命中,但没有数据传递,所有输入都为空.

(参数字典包含空条目...)

这是我的表格

 @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>
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?JQUERY Bug?

这里更新是我的控制器

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

和一些提琴手(已发送)

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
Run Code Online (Sandbox Code Playgroud)

以下是我提交的内容:

$("#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");
            }
        });
Run Code Online (Sandbox Code Playgroud)

我的HTML源代码

<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>
Run Code Online (Sandbox Code Playgroud)

Pin*_*nch 6

之前添加了这个 .submit()

 $("#dialog-formEthernet").parent().appendTo($("#FormEthernet"));
Run Code Online (Sandbox Code Playgroud)

并解决了!

看这里:

带有ASP.NET按钮回发的jQuery UI对话框

引用"Chad Rupper":主要是因为jquery使用DOM将对话框移到Form标签之外.将其移回到表单标记内,它应该可以正常工作.你可以通过检查Firefox中的元素来看到这一点.

代码:Robert MacLean

请原谅我把你们全部震撼!