0

--I've deleted the original text to try to clean the post up a bit--

--------EDIT-------------------------------------------------------------------------

Here is some more info not sure if it helps anyone that's ran into this issue before. Here is what my final object looks like in the JS script:

var DealerModel = {
    Dealer: {
        AccountId: 5678,
        Name: "Austin",
        City: "Who knows",
        State: "TN"
    },
    Test: 111,
    DealerCategories: [{Name: "Test1", Value:"Value1"},{Name:"Test2", Value:"Value2"}]
}

When I pass this into my controller via jquery it has the 111 value for Test, it shows that DealerCategories has 2 objects, but for both those objects as well as Dealer it shows NULL.

I've changed up the model/controller a few times and it seems no matter what if I pass in an object that has a sub json object it doesn't like that. I have a feeling this is something simple i'm missing.

4

2 回答 2

0

模型绑定器知道如何从 JSON 绑定数组,所以你只需要给他这样的东西:

var DealerModel = 
{
  Dealer : 'my_dealer_value_here',
  DealerContact = [] <- a list of Contrats here
}

我认为应该这样做。

于 2013-02-01T22:26:42.820 回答
0

如果您的问题是从通过 jQuery.post 发布简单的值(如字符串和数字)实现飞跃,您还可以提供 json 对象,如上面 Alex 列出的对象。

$.ajax({
  type: "POST",
  url: 'MYURL',
  data: {
     Dealer : {id:-1, accountId: '', name:'TheDealer'},
     DealerContact: [{FirstName:'ContactName',...},{...},...]
  }
});

那一点数据应该反序列化为您的对象。

于 2013-02-01T22:34:54.803 回答