Angular JS Pass json data to mvc controller in the form of list

120 views
Skip to first unread message

Dhilip R

unread,
Jul 25, 2019, 11:55:17 AM7/25/19
to Angular and AngularJS discussion

I need to pass json in the form of List to controller in Angular JS Post.

I have tried to send data in form of Json to get it as list in the MVC controller. But when I did it , I get only row count at MVC Controller. The variables in the list are null

Angular Js Controller

$scope.SaveTaxRange = function (){
var tableData = [];
    try {
        $('#tablTaxRange tbody tr').each(function (index, element) {
            //tableData = {};
            tableData.push({
                Min_amt: $(this).find('th:eq(0) input').val(),
                Max_amt: $(this).find('th:eq(1) input').val(),
                Tax_percent: $(this).find('th:eq(2) input').val(),
                Tax_type: $(this).find('th:eq(3) input').val(),

            });
            tableData.push({
                Min_amt: $(this).find('th:eq(0) input').val(),
                Max_amt: $(this).find('th:eq(1) input').val(),
                Tax_percent: $(this).find('th:eq(2) input').val(),
                Tax_type: $(this).find('th:eq(3) input').val(),

            });
        });

    }catch (e) { alert(e); }
$http({
        url: "/PayModule/Pay_mas_taxsetup",
        method: "Post",
        data: { "model": data }
}).then(function(response){});
};

MVC Model

public class TaxSetupMaster
{
    public class TaxRange
    {
        public string Min_amt;
        public string Max_amt;
        public string Tax_percent;
        public string Tax_type;
        public string add;
    }
    public List<TaxRange> lstTaxRangeSave { get; set; }
}

MVC Controller

[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
    public ActionResult Pay_mas_taxsetup( TaxSetupMaster model)
    {
        var a = model.lstTaxRangeSave ;//Here it shows rowcount 2 but the variables are null. Is it feasible to get the data from html? 
    }

Thanks in advance

Sander Elias

unread,
Jul 25, 2019, 12:04:16 PM7/25/19
to Angular and AngularJS discussion
Why are you trying to parse the DOM? can't you just reuse the data you used to build the table in the first place?

Regards
Sander
Reply all
Reply to author
Forward
0 new messages