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 order to pass the variable to an action in my controller.
I am doing something similar to this prior in my code with the exception of generating the form.
I have tried different methods and not matter what when I access the collection in my action the value is null.
My View function:
$('#myTable').on('click', 'td', function () {
var serial = table.cell(this).data();
var form = $('<form action="@Url.Action("status")" id="hiddenform"><input type="hidden" id="serial" name="serial" value=""></form>').appendTo('body');
$('.serial').val(serial);
form.submit();
});
and my controller I am parsing to:
//Accept GET and POST
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
public ActionResult Status(System.Web.Mvc.FormCollection collection)
{
string serial = collection["serial"];
if (serial == null || serial == "")
System.Windows.Forms.MessageBox.Show("Error: Serial is NULL");
return View(serial);
}
To be honest I have butchered my code a lot in an attempt to fix this so it looks pretty awful.
Any help would be appreciated.
I am receiving the Error: Serial is NULL popup every time in my controller. However if I test the JQuery the value is not null it returns the correct value.