I tried to make a partial view of a dropdown list to load data using ViewModel as context.categories.tolist(). and then Render the partial view on the layout page! but render page giving an error! asking the same ViewModel to pass! Have any idea how to design a dropdownlist on the layout page without using @model ViewModel !!?
public ActionResult CategoryDropDown()
{
HomeViewModel model = new HomeViewModel();
model.AllCategory = CategoriesService.Instance.allCategory();
//getting category list from database
return PartialView(model);
}
Views/Shared/_Layout.cshtml
<!DOCTYPE html>
<html>
<header>
all the headers link///
</header>
<section>
@if (Model != null && Model.AllCategory.Count > 0)
{
<div class="col-lg-3">
<div class="hero__categories">
<div class="hero__categories__all">
<i class="fa fa-bars"></i>
<span>All departments</span>
</div>
<ul>
@foreach (var category in Model.AllCategory)
{
<li><a href="#">@category.Name</a></li>
}
</ul>
</div>
</div>
}
</section>
Renderbody()
@RenderSection("scripts", required: false)
</html>
~~