Display a view in _Layout.cshtml?

I have followed this tutorial to generate a dynamic list menu http://dotnetawesome.blogspot.se/2014/06/how-to-create-treeview-with-database-data-mvc4-aspnet.html

This is the view

@model List<Project.Models.Treeview>

@{
    ViewBag.Title = "Simple";
}

<h2>Simple Treeview from Database Data</h2>
<div style="border:solid 1px black; padding:10px; background-color:#FAFAFA">
    <div class="treeview">
        @if (Model != null && Model.Count() > 0)
        {
            <ul>
                @Treeview.GetTreeView(Model, Model.FirstOrDefault().ParentCategoryID)
            </ul>
        }
    </div>
</div>

@* Here We need some Jquery code for make this treeview collapsible *@
@section Scripts{
       <script>
            $(document).ready(function () {
                $(".treeview li>ul").css('display', 'none'); // Hide all 2-level ul
                $(".collapsible").click(function (e) {
                    e.preventDefault();
                    $(this).toggleClass("collapse-tree expand-tree");
                    $(this).closest('li').children('ul').slideToggle();
                });
            });
        </script>
         } 

And it works fine but instead of having it in a separate view I want to integrate it it my main manu. I want to display the result from the view above in the code below where I have the text “Display here”.
_Layout.cshtml

            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
Display here!!
                        <li>@Html.ActionLink("Video", "Index", "Video")</li>
                        <li>@Html.ActionLink("Photos", "Index", "Photos")</li>
</ul>
<div> 

I have looked into Partial View and Html.RenderAction but don’t know what to use


Source: .net

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.