有趣的問題。提交按鈕不提交
在項目範圍更改中,我將一個應用程序分爲兩個應用程序。我創建了一個新項目,而不是試圖將現有的應用程序分解爲兩個,並重用了以前編寫的大部分代碼。我陷入了讓我把頭髮拉出來的最後一個錯誤。
我有一個項目列表,每行都有一個複選框,以允許用戶一次處理多行。我有一些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,現在我得到一個空例外。我發佈的值是DropDownAction=P&CbSelect%5B%5D=274680&CbSelect%5B%5D=275744
。爲什麼不能public ActionResult Index(int[] CbSelect, string DropDownAction)
工作?我在的DropDownAction
和null
中得到正確的值。
您能否詳細說明您如何解決這個問題? – Shimmy 2013-04-29 13:02:11
這已經超過2年前了...除了我在那裏之外不再有了。 – 2013-04-29 14:42:13
看看[這個](http://stackoverflow.com/questions/16193615/asp-net-mvc-form-doesnt-submit-to-the-right-action)的問題? – Shimmy 2013-04-29 15:35:34