I solved my problem, I should have changed code inside GetAll
method in CategoryService
this way :
public IList<Category> GetAll()
{
return _category.Where(category => category.ParentId == null)
.Include(category => category.Children).ToList();
}
Then In my partial view :
@model IEnumerable<SarbarzDarb.Models.Entities.Category>
@foreach (var item in Model)
{
<li class="dropdown">
@Html.ActionLink(item.Name, actionName: "Category", controllerName: "Product", routeValues: new { Id = item.Id, productName = item.Name.ToSeoUrl() }, htmlAttributes: null)
<ul class="dropdown-menu">
@foreach (var child in item.Children)
{
<li class="dropdown">
@Html.ActionLink(child.Name, "Category", "Product", new { Id = child.Id, productName = child.Name.ToSeoUrl() }, null)
</li>
}
</ul>
</li>
}