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
.