0

Im completeley new in mvc

I have creating an MVC project using the code first I have these three models: first is Category model which includes the main categories:

 public class Category
{
    public virtual int Id { get; set; }
    [Required]
    public virtual string CategoryName { get; set; }
    public virtual List<SubCategory> SubCategories { get; set; }

}

each category has some SubCategory

 public class SubCategory
{
    public virtual int Id { get; set; }

    public virtual int CategoryId { get; set; }
    [Required]
    public virtual string SubCategoryName { get; set; }
    public virtual Category Category { get; set; }
    public virtual List<Question> Questions { get; set; }

}

and each Sub Category has a list of Questions:

public class Question
{
    public virtual int Id { get; set; }
    public virtual int SubCategoryId { get; set; }
    public virtual string Qu { get; set; }

    [AllowHtml]
    [UIHint("tinymce_full_compressed")]
    public virtual string Ans { get; set; }
    public virtual List<KeyWord> KeyWord { get; set; }


    public virtual SubCategory SubCategory { get; set; }


}

I have used Scaffolding in Asp.net MVC to create a page which user could insert it's question. but before inserting the question user had to choose it's category and then its subcategory ,( both with dropdown selector ) and then write it's question and answer text. but the result of scaffolding is a little complicated.

@model FinalSearch5.Models.Question

enter image description here

it shows all sub categories with no ability to choose category first,and If I have two subcategory with same name but different category no way to find out which one to choose.

I know I need to add another drop-down and initialize it with the list which is available in category list and then call ajax but first of all I don't know what to change in my model.I create this view model to replace with question model but still dosent work properly.I need some advice how to implement this kind of cascadin dropdownlist

 public class CategorySubCategoryViewMoel
{
    public Category Category { get; set; }
    public SubCategory SubCategory { get; set; }
    public ICollection<Question> Questions { get; set; }

}
neda Derakhshesh
  • 1,103
  • 2
  • 20
  • 43

0 Answers0