I am using ASP.NET MVC and jQuery.
I have a textbox and an HTML table with data in, for example:
<form action="/Server/Test" method="post">
<input type="text" id="ServiceAccount" />
<table>
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
</tr>
<tr>
<td>Cell data 1</td>
<td>Cell data 2</td>
</tr>
</table>
</form>
The table above is not bound to a view model, it gets populated via AJAX/JSON.
I need the value of the textbox and the cell data to be posted to my controller's action method. So if I typed in 1234567 in the textbox then I need this value posted to the action method together with the contents of the table. I need the table data also for processing. Is this possible? I can't find a sample.
My action method looks like this:
[HttpPost]
public ActionResult Test(string[] data)
{
// Use the value Cell data 1
// Use the value Cell data 2
return View();
}
Given my code below it is not hitting my action method:
$('form').submit(function () {
$.post('@Url.Action("Test", "Server")', $('form').serialize(), function (data) {
alert('success');
});
return false;
});
I'm not understanding what I am doing wrong.