admin管理员组文章数量:1305181
I have converted a html table content in a array but unable to send it to the controller. Pls help
- I have tried a lot of references but every time the parameter in controller getting null values
function sendtabledata() {
var element = document.getElementById("pveloandata");
var rows = element.querySelectorAll("tr");
var jsarray = [];
rows.forEach((r, i) => {
if (i > 0) {
const tabledata = {}
const rowitems = r.children
tabledata["srl"] = i;
tabledata["date"] = rowitems[1].textContent;
tabledata["balance"] = rowitems[2].textContent;
tabledata["intbal"] = rowitems[3].textContent;
jsarray.push(tabledata);
}
})
jsarray = JSON.stringify({ 'jsarray': jsarray });
$.ajax({
ContentType: 'application/json; charset=utf-8',
dataType: "json",
type: "POST",
traditional:true,
url: '@Url.Action("gettabledata", "Loan")',
data: jsarray,
success: function (data) {
},
error: function (err) {
alert(err);
}
});
}
//controller Method
public ActionResult gettabledata(string[] jsarray)
{
return View();
}
I have converted a html table content in a array but unable to send it to the controller. Pls help
- I have tried a lot of references but every time the parameter in controller getting null values
function sendtabledata() {
var element = document.getElementById("pveloandata");
var rows = element.querySelectorAll("tr");
var jsarray = [];
rows.forEach((r, i) => {
if (i > 0) {
const tabledata = {}
const rowitems = r.children
tabledata["srl"] = i;
tabledata["date"] = rowitems[1].textContent;
tabledata["balance"] = rowitems[2].textContent;
tabledata["intbal"] = rowitems[3].textContent;
jsarray.push(tabledata);
}
})
jsarray = JSON.stringify({ 'jsarray': jsarray });
$.ajax({
ContentType: 'application/json; charset=utf-8',
dataType: "json",
type: "POST",
traditional:true,
url: '@Url.Action("gettabledata", "Loan")',
data: jsarray,
success: function (data) {
},
error: function (err) {
alert(err);
}
});
}
//controller Method
public ActionResult gettabledata(string[] jsarray)
{
return View();
}
Share
Improve this question
asked Feb 4 at 11:13
Abhisek RoyAbhisek Roy
32 bronze badges
1
- Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Bot Commented Feb 4 at 15:27
1 Answer
Reset to default 0I can see issue with your post method below
jsarray = JSON.stringify({ 'jsarray': jsarray });
here you are sending
{"jsarray":[...]} instead of [...]
but you are accepting jsarray[] from server side
you need to update your from front end side like
jsarray = JSON.stringify(jsarray); //this will send array of element
on server side you can use like
public ActionResult gettabledata([FromBody]string[] jsarray)
本文标签: javascripthow to convert html table content to an array and send it to controllerStack Overflow
版权声明:本文标题:javascript - how to convert html table content to an array and send it to controller? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741770519a2396723.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论