我想使用JQuery将我的MVC表单序列化为JSON,然后想在C#后端反序列化一些值,如输入字段的值,但我无法将其序列化为json...请帮助我解决这个问题。以下是我的代码。
<script type="text/javascript">
$(function () {
$('#btnsearch').click(function (e) {
var searchname = $('#txtsearch').val();
var form = $(this).serializeArray();
DrawTable(form);
});
function DrawTable() {
var props = [];
props.push({ name: "FirstName", value: firstname });
BindDataTable({ AllowPaging: true, ShowFilter: false, ShowEditLink: true, EmptyTableText: 'No Data Found', SortIndex: 0, SortDirection: "asc" },
"#tblCustomers",
"@Url.Action("GetAllCustomers", "Customer")",
props,
[{ name: "Id", cellClass: "alignCenter", Sortable: true, index: 0 }, { name: "FirstName" }, { name: "ABN" }, { name: "Phone" }, { name: "Email" }, { name: "Address1" }, { name: "City" }, { name: "Country" }],
[{ name: "Id", type: "anchor", title: 'customerTable', viewtitle: 'View', link: '@Url.Action("Edit", "Customer")', index: 0 }]);
}
// DrawTable(data);
//$('#myInputTextField').on('keyup', function () {
// oTable.search($(this).val()).draw();
//});
});
</script>