1

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.

Mike Wills
  • 20,959
  • 28
  • 93
  • 149

4 Answers4

3

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.

Mike Wills
  • 20,959
  • 28
  • 93
  • 149
2

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.

Eric Clifford
  • 223
  • 3
  • 8
0

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?

automagic
  • 1,067
  • 8
  • 10
  • How do I verify what is getting sent? I added the generated HTML. Like I said, this worked in the previous application I copied this from. – Mike Wills Nov 08 '10 at 22:09
0

Have you changed your default routing?

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

Lee Smith
  • 6,339
  • 6
  • 27
  • 34