Json and ajax

Moti Mashiah
Moti Mashiah used Ask the Experts™
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

                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;
                        i.Cost = item.Cost;
                        i.LocalCost = item.Cost * Convert.ToDecimal(0.84);

return Json(lstsupliers, JsonRequestBehavior.AllowGet);

Open in new window

Here is my ajax call example:
function Nexttostepeight() {
    var manu = $("#textmanufactureid").val();
        type: "POST",
        url: "/PIM/Nexttostep8",
        dataType: "json",
        data: { manu: manu },
        success: function (data) {
            $('#step7').css('backgroundColor', '#2ECCFA')
            $('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);
            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;

Open in new window

The issue I'm facing here is - I'm getting the first properties just fine, but the rest come with error.
"Cannot read property 'MinimumOrder' of undefined"

Please, HELP.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
.NET Developer
I solved the issue.

I just had to change the array to 0  in all fields as it is the first object in json data. I learn something today :).:
 var dt1 = data[0].SupplierName;
            var dt2 = data[0].ReorderNumber;
            var dt3 = data[0].MinimumOrder;
            var dt4 = data[0].MasterPackQuantity;
            var dt5 = data[0].Customtext5;
            var dt6 = data[0].Cost;
            var dt7 = data[0].LocalCost;

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial