Skip to content Skip to sidebar Skip to footer

Generating Form With Hidden Input And Submitting To An Action

I thought this would be a lot simpler than it had been. I need to extract data from a cell in my datatable (Which I can do) and then submit it via a form with a hidden field in ord

Solution 1:

Have you tried changing the method signature to the following?

public ActionResult Status(string serial)

where serial will be the parameter name that you will pass from the HTML form.

If the parameter name is blah in HTML, you might have to change your method signature to below:

public ActionResult Status(string blah)

Solution 2:

Your hidden field has a name and id property of serial, but the jQuery selector used to assign a value is looking for a class. Try # instead to select by ID:

$('#serial').val(serial);

Alternatively you can use jQuery to AJAX POST the data to your controller:

$.post( '@Url.Action("status")', { serial: table.cell(this).data() } );

And adjust your controller to expect a parameter of serial:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Status(string serial)
{
    if (serial == null || serial == "")
        System.Windows.Forms.MessageBox.Show("Error: Serial is NULL");

    return View(serial);
}

Post a Comment for "Generating Form With Hidden Input And Submitting To An Action"