這個礦的博客文章可以幫助你很多:
Asp.net MVC model binding to List<T>
但基本上,您會爲您的IncomeDeclaration
提供字段,然後根據需要動態添加ActivityIncomeDeclaration
字段。
如果你想實際序列化表單,你將不得不遵循上部博文中提供的指令。
但如果您使用jQuery,還有第二種選擇。你可以操縱一個複雜的JavaScript對象,它會像在同一個服務器端的C#類的副本:
var incDec = {
Name: ""
// and other properties
ActivityIncomeDeclarations: []
};
然後同時用戶將被添加這些ActivityIncomeDeclarations你永遠只需撥打
incDec.ActivityIncomeDeclarations.push({
// properties
});
然後我的其他博客文章將幫助您可在此對象轉換爲一個字典,jQuery的例如是輕易就能過程:
Sending complex JSON objects to Asp.net MVC using jQuery
通過使用prlogin博客文章,您可以輕鬆做到:
$.ajax({
url: "someURL",
type: "POST",
data: $.toDictionary(incDec),
success: function(data, status, xhr){
// process success
},
error: function(xhr, status, err){
// process error
}
});
您的意思是繼承嗎? – Aliostad 2011-02-22 19:25:31
否..許可證has_many活動...許可證has_many(IncomeDeclarations ..年度基準)..每個收入聲明都會有很多活動,因爲當他聲明 – ignaciofuentes 2011-02-22 19:31:19