asp.net-mvc – 允许操作和视图和模型的高度变化
我正在设计一个产品管理系统.我想知道在我的应用程序中处理每个Action / View中的大量变化的最佳方式.该应用程序可处理20个类别和12个目标市场,每个目标市场都会影响每个产品需要收集的数据.例如,“QuickAdd”操作包含核心数据,如产品名称和SKU,以及基于产品添加到的类别和目标市场的组合的其他几个关键信息(下面的示例).类别和目标市场不是产品的可配置属性,使用系统的用户只能在特定组合下工作,例如Toys / USA.提到这一点的原因是,我无法设计表单以具有每个类别/市场组合的属性部分,它需要按照类别/市场的形式进行工作 – 用户不了解其他组合.
有些例子希望澄清可能的情况:
所以问题是,在ASP.NET MVC中,什么是处理显示所有这些动态表单和处理发送到操作的数据变体的最好方式? 编辑 解决方法
我将为属性类型创建一些域模型.
public enum AttributeTypeEnum { Currency,Range,List,Number,Text,Boolean } public interface class IAttribute { int Id { get; set; } string Name { get; set; } AttributeTypeEnum AttType { get; set; } } public abstract class BaseAttribute { int Id { get;set;} string Name { get;set;} AttributeTypeEnum AttType { get; set; } } public class RangeAttribute<T> : BaseAttribute { T StartValue { get;set; } T EndValue { get; set; } } 然后将每个属性关联到一个或多个类别 public class CategoryAttribute { int Id { get; set; } IAttribute Attribute { get; set; } } 然后可以根据每个类别列出属性列表 public class CategoryAttributeService() { public IList<CategoryAttributes> GetAttributes(int CategoryId) { return new IList<CategoryAttributes>(); } } 然后,您的控制器可以在ViewData.Model中返回这些属性的列表. // controller action public class CategoryAttributeController : Controller { public ActionResult CategoryAttributes(int categoryId) { CategoryAttributeService cas = new CategoryAttributeServices(); ViewData.Model = new CategoryAttributeViewData(categoryId) { Attributes = cas.GetAttributes(categoryId); }; return View(); } } 并且让您的视图处理每个项目的类型,并相应地更改每个项目的表单控件/显示,即(具有开始和结束值的范围)布尔值将具有复选框,材料可能是列表框等. <%@ Page Title="" Language="C#" Inherits="ViewPage<CategoryAttributeViewData>" %> <% foreach(CategoryAttribute attribute in ViewData.Model.Attributes) { %> <%= Html.RenderAttribute(attribute) %> <% } %> 和辅助方法如 public static string RenderAttribute(this HtmlHelper,ICategoryAttribute att) { StringWriter stringWriter = new StringWriter(); using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter)) { switch(att.AttributeType) { case AttributeDataType.Boolean: CreateCheckBox(writer,att); break; case AttributeDataType.List: CreateListBox(writer,att); break; // Other types } } stringWriter.ToString(); } 编辑:我已经离开市场了,所以如果我明白这一点,每个市场都有一些类别(一对多)说美国和服装. >市场列表 市场>市场分类> CategoryAttributes>属性> AttributeMarkets 那是对的吗? 苹果电脑. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – ASP.NET MVC从c#代码创建绝对url
- asp.net – 从源代码,aspx,xaml中提取可本地化的字符串到资
- asp.net-mvc – 支持Asp.NET MVC Razor的编辑器
- asp.net – 在回发上设置viewstate
- asp.net – 我如何计算出我的服务器可以处理的最大负载?
- asp.net-mvc-4 – ASP.NET优化 – 捆绑
- asp.net-mvc – 使用401发送消息:Asp.net Web-api
- asp.net – How2:在HttpModule中挂钩的事件,用于将js链接放
- asp.net-mvc – 在应用程序洞察中设置用户名
- 使用ASP.NET窗体身份验证的WCF服务