Javascript Datatable未在表单提交时将rowid返回给asp.net mvc控制器
我无法在表单提交时将jquery数据表中的rowid获取到我的控制器 请在下面找到html代码:Javascript Datatable未在表单提交时将rowid返回给asp.net mvc控制器,javascript,jquery,asp.net-mvc,datatable,Javascript,Jquery,Asp.net Mvc,Datatable,我无法在表单提交时将jquery数据表中的rowid获取到我的控制器 请在下面找到html代码: <form id="frm-example" action="@Url.Action("Index", "Home")" method="POST"> <table id="example" class="display select" cellspacing="0" width="100%"> <thead>
<form id="frm-example" action="@Url.Action("Index", "Home")" method="POST">
<table id="example" class="display select" cellspacing="0" width="100%">
<thead>
<tr>
<th><input name="select_all" value="1" type="checkbox"></th>
<th>User ID</th>
<th>User Name</th>
</tr>
</thead>
</table>
<hr>
<p>
<input type="button" value="Add" class="btn btn-success" onclick="location.href='@Url.Action("Create", "UserProfile")'" />
<button type="submit" id="frm-example" class="btn btn-danger" value="Delete">Delete</button>
</p>
<pre id="example-console">
</pre>
</form>
主控制器的索引操作中的值显示为null。看起来您正在向控制台写入表单序列化的内容。你在javascript控制台中看到了什么?这里有很多代码。。。复制该问题是否需要全部信息?例如,我非常确定
updateDataTableSelectAllCtrl
与当前的问题无关。请阅读:@Kyle Gobel-我已经更改了代码,它应该返回rowid的数组,但现在它返回null到action方法
// Handle form submission event
$('#frm-example').on('submit', function (e) {
var form = this;
console.log('ids: ', rows_selected)
$.ajax({
type: 'post',
url: '',
data: {
id:JSON.stringify(rows_selected)
},
success: function (response) {
console.log("You data will be saved, resposnse: ", response);
}
});
return false
});
namespace DOSApplication.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string[] id)
{
return View("Index");
}
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
}
// Handle form submission event
$('#frm-example').on('submit', function (e) {
var form = this;
console.log('ids: ', rows_selected)
$.ajax({
type: 'post',
url: '',
data: {
id:JSON.stringify(rows_selected)
},
success: function (response) {
console.log("You data will be saved, resposnse: ", response);
}
});
return false
});