私がしたいのはこれです。
フォームを送信すると、フォームの値がコントローラに渡され、値が変換されてデータテーブルに返されます。
私はjsonデータをコントローラからデータテーブルに戻す方法を知っています。
また、フォーム値をAjax.BeginFormによってコントローラに渡す方法も知っています。
しかし、私は両方を行う方法がわかりません。
固定jsonデータをデータテーブルに返すだけのコードです。
フォーム値をコントローラに渡して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