We help IT Professionals succeed at work.

Json and ajax

Moti Mashiah
Moti Mashiah asked
Last Modified: 2017-04-07
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

.NET Developer
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions