umbracoumbraco-mvc

Umbraco Razor - binding content fields


I've created a template (View) in Umbraco (MVC) and am trying to figure out how to bind to the document type content. Keeping it really simple:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
    Layout = null;
}

<h1>@Model.Title</h1>

My Umbraco document type has a Title field (alias is 'title') but if I try and run this I get build errors. I've found a whole load of documentation suggesting using a Library.NodeById() method but I believe that's for WebForms and not MVC. Can anyone offer some guidance?


Solution

  • You can get a property value in multiple ways with Model::

    @Model.Content.GetPropertyValue("title")
    
    @Model.Content.GetProperty("title").Value
    

    And as a dynamic

    @CurrentPage.Title
    

    Did you remember to add your template to your document type?