ASP.NET MVC编辑集合的最佳实践 - 您的意见 [英] ASP.NET MVC Editing A Collection Best Practices - Your Opinion

查看:128
本文介绍了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 )
{
 ....
}

这篇关于ASP.NET MVC编辑集合的最佳实践 - 您的意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆