提交按钮不提交

发布于 2024-10-01 01:57:33 字数 1848 浏览 2 评论 0原文

有趣的问题。

在项目范围变更中,我将一个应用程序分解为两个应用程序。我创建了一个新项目,而不是尝试将现有应用程序一分为二,并重用了以前编写的大部分代码。我被最后一个让我拔掉头发的虫子所困扰。

我有一个项目列表,每行都有一个复选框,以允许用户一次处理多行。我有一些 jQuery 验证逻辑来​​确保在下拉列表中选择一个选项并且至少选择一行。这是有效的,但是当我单击提交按钮时似乎没有发生任何事情。我什至在函数的第一行代码上设置了一个断点,但它从未被触发。除了将操作从 Display 更改为 Index 之外,代码是相同的。有什么想法吗?

代码如下:

<% using (Html.BeginForm("Index", "Timesheet", FormMethod.Post, new { Id = "form1" }))
   { %>
<%= Html.DropDownList("DropDownAction", new SelectList(Model.Actions, "Value", "Text"), "(Select)", new { Class = "required" })%>
<input type="submit" value="Submit" />
....
<% } %>

TimesheetController.cs

    //
    // GET: /Timesheet/
    [Authorize]
    public ActionResult Index()
    {
        ....
    }

    //
    // POST: /Timesheet/
    [HttpPost, Authorize]
    public ActionResult Index(int[] CbSelect, string DropDownAction, SupervisorCredentials user)
    {
        foreach (int id in CbSelect)
        {
            ...

        }

        return RedirectToAction("Index");
    }

生成的 HTML:

<form Id="form1" action="/Timesheet" method="post"><select Class="required" id="DropDownAction" name="DropDownAction"><option value="">(Select)</option>
<option value=" ">Approve</option>
<option value="P">Paper Signature</option>
<option value="A">Absent Employee</option>
</select>
<input type="submit" value="Submit" />

更新:我删除了 jQuery,现在我收到一个 null 异常。我发布的值为 DropDownAction=P&CbSelect%5B%5D=274680&CbSelect%5B%5D=275744。为什么 public ActionResult Index(int[] CbSelect, string DropDownAction) 不起作用?我在 DropDownAction 中得到了正确的值,在 CbSelect 中得到了 null

Interesting problem.

In a project scope change, I broke one application into two applications. I created a new project instead of trying to hack the existing application into two and reused much of the previously written code. I am down the the final bug that is making me pull my hair out.

I have a list of items with a checkbox in each row to allow the user to work with multiple rows at a time. I have some jQuery validate logic to make sure an option is selected on a dropdown and at least one row is selected. This works, however nothing seems to happen when I click the submit button. I even set a breakpoint on the first line of code in the function and it is never triggered. The code is the same with the exception of changing the action from Display to Index. Any thoughts?

Code follows:

<% using (Html.BeginForm("Index", "Timesheet", FormMethod.Post, new { Id = "form1" }))
   { %>
<%= Html.DropDownList("DropDownAction", new SelectList(Model.Actions, "Value", "Text"), "(Select)", new { Class = "required" })%>
<input type="submit" value="Submit" />
....
<% } %>

TimesheetController.cs

    //
    // GET: /Timesheet/
    [Authorize]
    public ActionResult Index()
    {
        ....
    }

    //
    // POST: /Timesheet/
    [HttpPost, Authorize]
    public ActionResult Index(int[] CbSelect, string DropDownAction, SupervisorCredentials user)
    {
        foreach (int id in CbSelect)
        {
            ...

        }

        return RedirectToAction("Index");
    }

Generated HTML:

<form Id="form1" action="/Timesheet" method="post"><select Class="required" id="DropDownAction" name="DropDownAction"><option value="">(Select)</option>
<option value=" ">Approve</option>
<option value="P">Paper Signature</option>
<option value="A">Absent Employee</option>
</select>
<input type="submit" value="Submit" />

Update: I removed the jQuery and now I am getting a null exception. My posted values are DropDownAction=P&CbSelect%5B%5D=274680&CbSelect%5B%5D=275744. Why wouldn't public ActionResult Index(int[] CbSelect, string DropDownAction) work? I get the right value in DropDownAction and a null in CbSelect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

_畞蕅 2024-10-08 01:57:34

您是否更改了默认路由?

此外,您发布的 html 没有结束 标记。在那里吗?

Have you changed your default routing?

Also, the html you posted does not have a closing </form> tag. Is it there?

谜泪 2024-10-08 01:57:33

不知道为什么,但显然在我的 jQuery 验证部分,我有 debug: true。看起来这会阻止表单的实际提交。我不知道那是怎么到那里的。我没有添加它。不过,该表格现在可以使用了。

Not sure why, but apparently in my jQuery validate section, I had debug: true. It appears like that prevents the form from being actually submitted. I have no idea how that got there. I didn't add it. The form works now though.

鲜血染红嫁衣 2024-10-08 01:57:33

调试这些类型的情况可能会非常令人沮丧。给自己找一个像 http://www.fiddler2.com/fiddler/version.asp 启动它,它将监视所有网络请求,以便您可以轻松查看响应是什么,并查看您的表单是否真正提交。

It can be very frustrating to debug these types of situations. Get yourself a tool like http://www.fiddler2.com/fiddler/version.asp fire it up and it will monitor all web requests so you can easily see what the response is and see if your form is truly submitting.

坏尐絯 2024-10-08 01:57:33

考虑到 Action 的方法签名,表单中实际发布的内容可能与 MVC 期望的内容不匹配。如果它根本没有发布(即从未访问服务器,可以使用 firebug 或类似的方法进行验证),那么您的视图的 HTML 输出是什么样的?

Its likely what is actually getting posted in the form, does not match what MVC expects given the method signature of your Action. If its not even posting at all (ie never hitting the server, can be verified with firebug or similar), what does the HTML output of your view look like?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文