【发布时间】:2013-11-06 03:43:45
【问题描述】:
我正在使用 EF 和 MVC 4 开发网络商店应用程序
我有一个产品域模型:
public class Product
{
public int Id{ get; set;}
public decimal InitialPrice { get;set;}
public string Name {get;set;}
public byte ProductCategoryId { get;set; }
public ProductCategory ProductCategory{get;set;}
public List<ProductProperty> ProductProperties
{get{return ProductCategory.ProductProperties }}
}
在此域模型中,ProductProperty 列表依赖于 ProductCategoryId,因为每个 ProductProperty 都分配给 ProductCategories 之一。
因此,在创建视图中,当 ProductCategoryId DropDownList 发生更改时,应该为每个 ProductProperty 引用选定的 ProductCategoryId 出现几个其他 DropDownList。为了实现这一点,我在 Razor 视图中使用此代码在 DropDownList 更改上提交表单:
@Html.DropDownListFor(model => model.ProductCategoryId, (SelectList)ViewBag.ProductCategoriesSelectList, "Select", new { onchange = "submit()"})
现在在我的控制器视图中,我需要知道表单是通过保存按钮还是下拉更改事件提交的,以跳过验证和保存操作。
问题是:
有没有更好的方法来处理在视图中为每个 ProductProperties 引用到选定的 ProductCategory 添加 DropDownLists?
以及如何确定表单是通过保存按钮还是下拉列表更改提交的?
【问题讨论】:
-
我会为此使用 ajax。在这里查看问题stackoverflow.com/questions/14339089/…
标签: c# asp.net asp.net-mvc razor