Calling partial view from _Layout.cshtml

后端 未结 1 720
一个人的身影
一个人的身影 2021-01-24 08:53

I have a main category and main category has its subcategory list in database. So its a relational database. For better understanding .edmx map picture is attached. Now my goal

相关标签:
1条回答
  • 2021-01-24 09:34

    1.Change @Html.Partial("_GuestNav") to @{Html.RenderAction("_GuestNav", "YourControlerName");}

    2.Add @Model TypeofYourViewModel on top of your partial view.

    3.Change the looping as follows:

    @foreach (var item in Model)
        {
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">@item.MainCatName<span class="caret"></span></a>
                <ul class="dropdown-menu" role="menu">
                    @foreach (var subcat in item.subcat)
                    {
                        <li><a href="#">subcat.SubcatName</a></li>
                    }
                </ul>
            </li>
        }
    

    Note: Change TypeofYourViewModel to whatever ViewModel you are passing into the partial view

    0 讨论(0)
提交回复
热议问题