Hi Guys,
I was given a task to generate dependent values in DropDownList without using jQuery. However this approach is not recommended but incase you still want to generate the dependent dropdownlist values based upon the parent dropdownlist value, Here are the steps to do so.
In my example i am using an example of Category, SubCategory and Product. Based on the category dropdown, subcategory dropdown list is generated and the product is then saved based on the category and subcategory values. In this example i have taken both category and subcategory reference in product table, However it can be done by taking only reference of subcategory table.
Step 1: Generate models
public class Category
{
[Key]
public virtual int CategoryId { get; set; }
public virtual string CategoryName { get; set; }
public List<SubCategory> SubCategories { get; set; }
public List<Product> Products { get; set; }
}