gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:31:30 25 4
gpt4 key购买 nike

鉴于以下类(class),您对处理创建/编辑的最佳方式有何看法,其中 Attributes.Count 可以是任意数字。

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;}
}

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

处理模型中的更改很容易,处理 UI 和 ActionMethod 方面的最佳方法是什么?

最佳答案

使用 FormCollection 并遍历键/值对。据推测,您可以使用命名方案来确定哪些键/值对属于您的属性集。

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

关于asp.net-mvc - ASP.NET MVC 编辑集合最佳实践 - 您的意见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/289082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com