troubleshooting Question

Json and ajax

Avatar of Moti Mashiah
Moti MashiahFlag for Canada asked on
ASP.NETAJAXJSON
1 Comment1 Solution214 ViewsLast Modified:
Hi guys,
I'm about to lose my mind :).

I have asp.net mvc project and I'm returning json to ajax call from the controller.
Look at my backend method:
public JsonResult Nexttostep8(string manu)
{
var supllst = (from i in dbh.Items
                               join s in dbh.SupplierLists on i.ID equals s.ItemID
                               join sa in dbh.Suppliers on s.SupplierID equals sa.ID
                               where i.ItemLookupCode == "050326120180"
                               select new
                               {
                                   sa.SupplierName,
                                   s.ReorderNumber,
                                   s.MinimumOrder,
                                   s.MasterPackQuantity,
                                   s.Cost,
                                   sa.CustomText5
                               }).ToList();


                foreach (var item in supllst)
                {
                    var i = new suppliersmodel();
                    i.SupplierName = item.SupplierName;
                    i.ReorderNumber = item.ReorderNumber;
                    i.MinimumOrder = item.MinimumOrder;
                    i.MasterPackQuantity = item.MasterPackQuantity;
                    i.Customtext5 = item.CustomText5;

                    if (item.CustomText5 == "LOCAL")
                    {
                        i.Cost = item.Cost;
                        i.LocalCost = item.Cost;
                    }
                    else
                    {
                        i.Cost = item.Cost;
                        i.LocalCost = item.Cost * Convert.ToDecimal(0.84);
                    }

                    lstsupliers.Add(i);
                }
return Json(lstsupliers, JsonRequestBehavior.AllowGet);
}
Here is my ajax call example:
function Nexttostepeight() {
    var manu = $("#textmanufactureid").val();
    $.ajax({
        type: "POST",
        url: "/PIM/Nexttostep8",
        dataType: "json",
        data: { manu: manu },
        success: function (data) {
            $('#step7').css('backgroundColor', '#2ECCFA')
            $('#step7').addClass('disabled');
            $('ul.setup-panel li:eq(7)').removeClass('disabled');
            $('ul.setup-panel li a[href="#step-8"]').trigger('click');
            $("#manufacturerprogresid").show().html("<strong>MANUFACTURER:</strong> " + manu);
            debugger;
            var suplier = '';
            for (var i = 0; i < data.length; i++) {
                var dt1 = data[0].SupplierName;
                var dt2 = data[1].ReorderNumber;
                var dt3 = data[2].MinimumOrder;
                var dt4 = data[3].MasterPackQuantity;
                var dt5 = data[4].Customtext5;
                var dt6 = data[5].Cost;
                var dt7 = data[6].LocalCost;
}
        }
    });
}
The issue I'm facing here is - I'm getting the first properties just fine, but the rest come with error.
like:
"Cannot read property 'MinimumOrder' of undefined"

Please, HELP.
ASKER CERTIFIED SOLUTION
Moti Mashiah
.NET Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros