0

Following is my partial view - Call to the controller is done using an ajax call below

$.ajax(url, {
            type: 'POST', 
            data: { Addresses: InboundAddresses },
            cache: false,
            crossDomain: true,
            success: function (data) {
                //Populate the form values
                // Start Dialog Code
                $myWindow = jQuery('#myDiv');
                //instantiate the dialog
                $myWindow.html(data);
                $myWindow.dialog({
                    title: 'Select an address',
                    modal: true,
                    width: 'auto'
                });
                $myWindow.show();
                $myWindow.dialog("open");
                // End Dialog Code

                $('#AddressTable').on('click', 'tr', function () {
//                    alert('You clicked row ' + ($(this).index()));
                    addAddress(InboundAddresses, Message, $(this).index())
                });
            },
            error: function (jqXHR, textStatus, errorThrown) {
                $('#Message').val('Kaboom!!! (The call blew up...#thatsucks)');
                alert('The Dialog Box call failed...Sorry :(');
            }
        });

I traced the code and the call is sending the contents correctly ( Verified in fiddler ) Receiving method in controller does have objects but content in those objects is null. I think this is a parsing issue.

See the code for method below.

public PartialViewResult ShowAddresses(List<Address> Addresses)
        {
            ShowAddressViewModel viewModel = new ShowAddressViewModel();
            viewModel.Addresses = Addresses;
            viewModel.Message = "NEW";
    return PartialView("_ShowAddress", viewModel);
}
6
  • What does your json data look like when it's being sent? Commented Oct 9, 2013 at 22:07
  • It is a list of address objects. Each address object has address1,2 , city,state,zip Commented Oct 9, 2013 at 22:09
  • and Address has the same properties that the each json objects has? Check each property name. Commented Oct 9, 2013 at 22:17
  • I am sorry. I am a noob. Can you explain what you meant by check each property name ? Commented Oct 9, 2013 at 22:21
  • public string city { get; set; } in your Address class Commented Oct 9, 2013 at 22:37

1 Answer 1

1

Each property on your json object your are passing must map to a property in your Adresss class

i.e.

public class Address
{
   public string address { get; set; }
   public string city { get; set; }
   // etc...
}

in your sample json data you say that you have address1, address2 that will not work, json object properties must match exactly.

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

1 Comment

I am using mvc3. this is what my address object looks like namespace PeopleSoftControlsPOC.Domain { public class Address : IAddress { public string Address1 { get; set; } public string Address2 { get; set; } public string City { get; set; } public string State { get; set; } public string Zip { get; set; } } }

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.