I'm Completely new in ASP.net MVC
I have two model first is category
public class Category
{
public virtual int Id { get; set; }
[Required]
public virtual string CategoryName { get; set; }
public virtual List<SubCategory> SubCategories { get; set; }
}
and next subcategory model:
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; }
}
I need to have a list of my categories and also a list of subcategories both in my view so this is my view model
public class CategorySubCategoryViewMoel
{
public ICollection<Category> Category { get; set; }
public SubCategory SubCategory { get; set; }
}
and here is my view
@model FinalSearch5.Models.CategorySubCategoryViewMoel
<ul>
@foreach (var category in Model.Category)
{
<li>@category.CategoryName</li>
}
</ul>
here is my controller
public ActionResult Index()
{
var cats = db.Categories.ToList();
return View(cats);
}
It's not implementing completely yet but until here there is an Error
The model item passed into the dictionary is of type 'System.Collections.Generic.List1[FinalSearch5.Models.Category], but this dictionary requires a model item of type 'FinalSearch5.Models.CategorySubCategoryViewMoel'.`
Appreciate if help me what is the problem thank you.