这个矿的博客文章可以帮助你很多:
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