We have moved!

You are currently looking at documentation for Umbraco 8 and older versions.
An automated guess is that docs.umbraco.com/umbraco-cms/reference/templating/mvc/examples could be the link to the new documentation for Umbraco 9 and newer versions.

    View/Razor Examples

    Lots of examples of using various techniques to render data in a view

    Rendering the raw value of a field from IPublishedContent

    @Model.Value("bodyContent")
    

    Rendering the converted value of a field from IPublishedContent

    @Model.Value<double>("amount")
    @Model.Value<IHtmlString>("bodyContent")
    

    Rendering a macro

    @Umbraco.RenderMacro("myMacroAlias")
    

    Rendering a macro with parameters using an anonymous object

    @Umbraco.RenderMacro("myMacroAlias", new { name = "Ned", age = 28 })
    

    Rendering a macro with parameters using a dictionary

    @Umbraco.RenderMacro("myMacroAlias", new Dictionary<string, object> {{ "name", "Ned"}, { "age", 27}})
    

    Rendering some member data

    @if(Members.IsLoggedIn()){
        var profile = Members.GetCurrentMemberProfileModel();
        var umbracomember = Members.GetByUsername(profile.UserName);
    
        <h1>@umbracomember.Name</h1>
        <p>@umbracomember.Value<string>("bio")</p>
    }