依赖于另一个属性的复杂类型列表的编辑器模板 [英] Editor Template for List of complex types that depends on another property

查看:80
本文介绍了依赖于另一个属性的复杂类型列表的编辑器模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发ASP.net MVC4网络应用程序。有Product,ProductProperty,ProductCategory模型:



I'm working on ASP.net MVC4 web app. There are Product, ProductProperty, ProductCategory models:

public class Product
{
    public int Id { get;set;}
    public string Name {get;set;}
    public byte ProductCategoryId { get; set;}
    public virtual ProductCategory ProductCategory {get; set;}
    public List<PropertyValue> PropertyValues {get;set;}
}

public class ProductProperty
{
    public int Id { get; set; }
    public string Name{ get;set;}
    public virtual List<PropertyValue> PropertyValues{get;set;}
    public virtual List<ProductCategory> ProductCategories{get;set;}
}

public class ProductCategory
{
    public byte Id {get;set;}
    public string Name { get; set;}
    public List<Product> Products;
    public virtual List<ProductProperty> ProductProperties {get; set;}
}







每件产品都属于类别,每件产品属性适用于一个或多个类别,产品型号具有依赖于类别的属性值列表。



我不知道如何实现产品的创建和编辑视图和控制器操作。



当产品发送到创建视图时,其类别未被选中,但在选择之后应该有回发或ajax,这将创建具有ProductProperties的PropertyValues的DropDownLists被引用选中类别。然后在最终发布后,带有PropertyValues列表的Product对象应保存在DB中。



这真令人困惑,如果有简单优雅的解决方案,请提供建议。



谢谢!




Each product reffers to category and each product property applies to one or more categories, Product model has List of property values which depends on category.

I do not know how to implement Create and Edit views and controller actions for products.

When product send to Create view its category is not selected, but after it selected there should be post back or ajax which would create DropDownLists with PropertyValues of ProductProperties reffered to selected Category. Then after final post Product object with List of PropertyValues should be saved in DB.

That is really confusing, please advice if there simple and elegant solution.

Thank you!

推荐答案

我会显示一个可用类别和属性的下拉列表,并弹出一个将新项添加到列表中。我希望这需要自己编写所有代码,而不是依赖于IDE可以自动生成的模板化代码。



我也使用实体框架(默认情况下)并期望EF会公开每个连接类型的所有子属性,因为数据库中存在适当的关系。
I'd show a drop list of available categories and properties, and a pop up to add new items to the list. I expect this would require writing all of the code yourself and not relying on the templated code that you can get auto generated by the IDE.

I'd also use entity framework ( by default ) and expect that EF would expose all the sub properties of each connected type, because of proper relationships in the database.


这篇关于依赖于另一个属性的复杂类型列表的编辑器模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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