.net - Display a view in _Layout.cshtml? -
i have followed tutorial generate dynamic list menu http://dotnetawesome.blogspot.se/2014/06/how-to-create-treeview-with-database-data-mvc4-aspnet.html
this view
@model list<project.models.treeview> @{ viewbag.title = "simple"; } <h2>simple treeview 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 need jquery code make treeview collapsible *@ @section scripts{ <script> $(document).ready(function () { $(".treeview li>ul").css('display', 'none'); // hide 2-level ul $(".collapsible").click(function (e) { e.preventdefault(); $(this).toggleclass("collapse-tree expand-tree"); $(this).closest('li').children('ul').slidetoggle(); }); }); </script> }
and works fine instead of having in separate view want integrate it main manu. want display result view above in code below have 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 partial view , html.renderaction don't know use
edit
file structure
controllers -- treeviewscontroller.cs models -- treeview.cs views shared -- _layout treeviews -- index.cshtml -- create.chhtml -- delete.chhtml
tested with
<li>@{html.renderpartial("index", "treeviews");}</li> <li>@{html.renderpartial("treeviews");}</li>
renamed file index (in views treevviews) _treeviews
<li>@{html.renderpartial("_treeviews");}</li>
ways render partial views
- html.renderpartial - faster
html.partial
- html.partial
use @{html.renderpartial("_partialviewname")}
render partial view
Comments
Post a Comment