Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I dug into MVC and Umbraco a bit more and created a solution that does use a custom controller. The basic appraoch is this.</p> <p>Create a Model in the Models folder of your project</p> <pre><code>namespace MyProject.Models { public class MenuModel { // My Model contains just a set of IPublishedContent items, but it can // contain anything you like public IEnumerable&lt;IPublishedContent&gt; Items { get; set; } } } </code></pre> <p>Create a new partial view in the Views > Shared folder</p> <pre><code>@inherits UmbracoViewPage @{ Layout = null; } &lt;ul&gt; @* Iterate over the items and print a link for each one *@ @foreach (var page in Model.Items) { &lt;li&gt;&lt;a href="@page.Url()"&gt;@page.Name&lt;/a&gt;&lt;/li&gt; } &lt;/ul&gt; </code></pre> <p>Create a SurfaceController to perform some business logic like fetching nodes and building the Model</p> <pre><code>using System.Web.Mvc; using MyProject.Models; using Umbraco.Core; using Umbraco.Web; using Umbraco.Web.Models; using Umbraco.Web.Mvc; namespace MyProject.Controllers { public class NavMenuController : SurfaceController { public ActionResult Render(RenderModel some) { // Get the current homepage we're under (my site has multiple, because it is multi-language) var currentHomePage = CurrentPage.AncestorOrSelf(1); // Create model object var menuModel = new MenuModel(); // Select descendant "Artikel" nodes of the current homepage and set them on the menu model menuModel.Items = currentHomePage.Descendants("Artikel").Where(x =&gt; x.IsVisible()); // Return the partial view called NavMenu // Do any processing you like here... return PartialView("NavMenu", menuModel); } } } </code></pre> <p>Call your new partial view from anywhere using this line of code:</p> <pre><code>@Html.Action("Render", "NavMenu") </code></pre> <p>I also posted this on our.umbraco.org:</p> <p><a href="http://our.umbraco.org/forum/developers/api-questions/45339-Umraco-6-Looking-for-the-MVC-equivalent-of-codebehind-file?p=0#comment163126" rel="nofollow">http://our.umbraco.org/forum/developers/api-questions/45339-Umraco-6-Looking-for-the-MVC-equivalent-of-codebehind-file?p=0#comment163126</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload