I'm using EF and MVC 4 to develop web store application
I have a Product domain model:
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 }}
}
In this domain model List of ProductProperty depends on ProductCategoryId because every ProductProperty assigned to one of ProductCategories.
Therefore in a Create View when ProductCategoryId DropDownList changed several other DropDownLists should appear for each of ProductProperty reffered to selected ProductCategoryId. To implement this I'm submitting the form on DropDownList change using this code in a Razor view:
@Html.DropDownListFor(model => model.ProductCategoryId, (SelectList)ViewBag.ProductCategoriesSelectList, "Select", new { onchange = "submit()"})
Now in my Controller View I need to know whether the form was submitted by save button or dropdown change event, to skip validation and save operations.
The questions are:
Is there a better way to deal with adding DropDownLists in a View for each of ProductProperties reffered to selected ProductCategory?
And how to determine whether form was submitted by save button or dropdownlist change?