0

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?

Ian
  • 33,605
  • 26
  • 118
  • 198

2 Answers2

2

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?

Morten OC
  • 1,784
  • 2
  • 23
  • 30
  • Yes I did add a template to a document type - those are useful thanks. Out of curiosity do you know if you can make an MVC Model based on a Document Type for strongly typed binding? – Ian Feb 14 '14 at 18:54
  • No, unfortunately not. I've never seen that before. Only if you make your own model and bind that to your view. – Morten OC Feb 14 '14 at 19:01
1

You can also use the Field helper method:

@Umbraco.Field("myFieldName")

nice thing about this helper is that you can also specify alternative fields (if the first one was empty.

You can find this back in the documentation: http://our.umbraco.org/documentation/reference/templating/Mvc/views#RenderingafieldwithUmbracoHelper

dampee
  • 3,392
  • 1
  • 21
  • 37