Что я хочу сделать, так это.
После отправки форм значения в формах передаются контроллеру, а значения преобразуются и возвращаются в datatable.
Я знаю, как вернуть данные json в файл данных с контроллера.
Также я знаю, как передавать значения формы контроллеру Ajax.BeginForm.
Но я не знаю, как это сделать.
Вот мой код, который просто возвращает фиксированные данные json в datatables.
Как передать значения формы контроллеру и вернуть значения в данные jQuery
Посмотреть
<script type="text/javascript">
function PullIntoTable() {
$('#example').dataTable({
"bDestroy": true,
"bAutoWidth": false,
"aoColumns": [
{ sWidth: '30%' },
{ sWidth: '10%' },
{ sWidth: '20%' },
{ sWidth: '20%' },
{ sWidth: '20%' }, ],
"sAjaxSource": '@Url.Action("Search", "SearchCompany")',
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
dataType: 'json',
type: "POST",
url: sSource,
data: aoData,
success: function (json) {
fnCallback(json);
}
})
}
});
};
</script>
<input type="submit" value="Search" onclick="PullIntoTable()" />
<table cellpadding="0" cellspacing="0" border="0" class="search_result" id="example" width="100%">
<thead>
<tr>
<th>Company</th>
<th>Location</th>
<th>Address</th>
<th>Status</th>
<th>Inactive</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</tfoot>
</table>
Контроллер
public class SearchCompanyController : Controller
{
[HttpPost]
public ActionResult Search()
{
var Result = new List<Result>()
{
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"},
new Result{Name="DummyCompany", Location="DummyLocation", Address="DummyAddress", Status="SL", Inactive="Y"}
};
return Json(
new { aaData = Result.Select(x => new[] { x.Name, x.Location, x.Address, x.Status, x.Inactive }) },
JsonRequestBehavior.DenyGet
);
}
}
public struct Result
{
public string Name { get; set; }
public string Location { get; set; }
public string Address { get; set; }
public string Status { get; set; }
public string Inactive { get; set; }
}
спасибо. Сейчас я увижу веб-сайт. – Nigiri