Quote:
$('#mytable tbody tr').each(function ()
{
var txtid = $(this).find('td').eq(0).text();
var txttitle = $(this).find('td').eq(1).text();
var txtvalue = $(this).find('td').eq(2).find('input').val();
var properties =
{
'ID': txtid,
'Title': txttitle,
'Value':txtvalue
};
});
console.log(prop);
$.ajax({
url: '/Home/Create',
type: 'POST',
data:
{
vm: { AvailableCatProperty: properties },
Your
each
callback creates
a local variable called
properties
, which will not be available outside of that function.
Outside of that function, you then log an unrelated and apparently undefined variable called
prop
.
Also outside of that function, you try to send a variable called
properties
in your AJAX request. But since you're not in the same function where that variable was declared, it is not defined.
You need to work out what format the data needs to be sent as. For example, to send an array of objects:
let properties = [];
$('#mytable tbody tr').each(function () {
const txtid = $(this).find('td').eq(0).text();
const txttitle = $(this).find('td').eq(1).text();
const txtvalue = $(this).find('td').eq(2).find('input').val();
const item = {
'ID': txtid,
'Title': txttitle,
'Value':txtvalue
};
properties.push(item);
});
console.log(properties);
$.ajax({
url: '/Home/Create',
type: 'POST',
data: {
vm: { AvailableCatProperty: properties },