ASP.NET MVC编辑集合的最佳实践 - 您的意见

问题描述:

,什么是你的最佳方式的意见来处理创建/编辑在这里Attributes.Count可以是任何数字。

Given the following class, what is your opinion on the best way to handle create/edit where Attributes.Count can be any number.

public class Product {
  public int Id {get;set;}
  public string Name {get;set;}
  public IList<Attribute> Attributes {get;set;}
}

public class Attribute {
  public string Name {get;set;}
  public string Value {get;set;}
}

用户应该能够编辑这两个产品的详细信息(名称)和属性在同一视图的详细信息(名称/值),包括添加和删除新的属性。

The user should be able to edit both the Product details (Name) and Attribute details (Name/Value) in the same view, including adding and deleting new attributes.

在模型处理的变化是很容易,有什么处理UI和东西方ActionMethod最好的方式?

Handling changes in the model is easy, what's the best way to handle the UI and ActionMethod side of things?

使用的FormCollection并通过键/值对迭代。 presumably你可以使用一个命名方案,让您以确定哪个键/值对属于你的属性设置。

Use the FormCollection and iterate through the key/value pairs. Presumably you can use a naming scheme that will allow you to determine which key/value pairs belong to your attribute set.

[AcceptVerbs( HttpVerb.POST )]
public ActionResult Whatever( FormCollection form )
{
 ....
}