我有以下問題:MVC 3 AJAX後,列表填充對象,但對象屬性爲空
在按鈕單擊我POST一些數據到服務器。 我控制器操作是這樣的:
public ActionResult Accept(List<MyViewModel> entries)
{
//here entries HAS 2 MyViewModel-Instances in it.
//The entries are not null, but the values of the instances are!
//entries[0].ParamA is null
}
凡MyViewModel看起來是這樣的:
public class MyViewModel
{
public string ParamA { get; set; }
public string ParamB { get; set; }
}
而AJAX的呼叫是follwing:
var myEntries = { entries: [{ ParamA: "A", ParamB: "B" }, { ParamA: "C", ParamB: "D" }] };
$.ajax({
type: 'POST',
url: url,
cache: false,
data: myEntries,
dataType: 'text' });
什麼我已經嘗試過要做:
- 更改數據類型爲 'JSON'
- 使用:傳統:真
- 試圖變種myEntries = JSON.stringify(...);
- 已嘗試var myEntries = {entries:[JSON.stringify({...}),JSON.stringify({...})]};
- 與上面相同,但使用jQuery.param(...,true);
- 使用IEnumerable或MyViewModel []代替列表。
- 我在做什麼錯在這裏以上
的任意組合?
非常感謝你,非常提前幫助我!
編輯
我(剃刀)查看是不是在這個時刻,它無關什麼有趣的事。我沒有使用任何HTML.TextBoxFor(或類似的)方法來填充myEntries-Variable。它實際上是動態填充的(因爲有許多條件)。 爲了這個問題(和我自己的測試)我硬編碼變量。 :)
您可以發佈您(剃刀)視圖的代碼? – 2012-04-11 07:55:35
我的觀點沒有什麼有趣的地方。我在我的問題中明確了它。請參閱編輯部分 – Shion 2012-04-11 07:59:43
我有答案!我會盡快發佈(必須等待8小時...) – Shion 2012-04-11 08:25:19