1

I am able to pass my Model to the view with the following Code in controller

Models.Models.AELeadInfo lead = new Models.Models.AELeadInfo();
lead.firstName = "name";
lead.lastName = "lastname";
lead.add1 = "add1";
lead.add2 = "add2";
lead.city = "city";
lead.state = "state";
lead.zip = "zip";
lead.birthDay = "bday";
lead.phone = "phone";
lead.email = "email";
lead.preferedContact = "prefContact";

//do DB stuff
// return model
return Json(lead, JsonRequestBehavior.AllowGet);

My Jquery:

$.ajax({
    datatype: "json",
    url: "/Home/loadLeadInfo/",
    type: 'GET',
    contentType: 'application/json; charset=utf-8',
    data: { 'leadPhone': lph},
    success: function (data) {             
        $("#ld1_lastName").val( data.LastName);
        alert(data.LastName);
    },
});

I can see that everything is there when I hover over data in Chrome dev tools, but data.lastName returns undefined. I must be missing something simple here, been trying things and googling for hours with no luck.

1
  • 1
    Your code has an uppercase L in LastName, in the C# its a lower case l, case does matter, have you tried data.lastName Commented Nov 13, 2014 at 20:28

1 Answer 1

3

Refer it as:

data.lastName

And not as:

data.LastName

After all, you declared it with a lower case l and not L and JavaScript is case-sensitive.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.