versionFrom | versionRemoved |
---|---|
7.0.0 |
8.0.0 |
Covers how you convert common syntax in Umbraco Masterpages to Umbraco Views.
Masterpage
<%@ master language="C#" masterpagefile="~/masterpages/umbMaster.master">
Razor View
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout= "~/Views/umbMaster.cshtml";
}
Masterpage
<form runat="server">
Razor View
Remove, not required in views
Masterpage
<asp:content contentplaceholderid="footer">
<p>Hello</p>
</asp:content>
Razor View
@section footer {
<p>Hello</p>
}
Masterpage
<asp:contentplaceholder id="footer">
Razor View
@RenderSection("footer")
If the View that inherits from this view is not required to define a "footer" section then you can add an extra false
parameter (if you omit the boolean, it defaults to true
):
@RenderSection("footer", false)
If you want to render the main body area then you can do the following (only allowed once per View):
@RenderBody()
Masterpage
<umbraco:item field="bodyText" />
Razor View
@CurrentPage.bodyText
Masterpage
<umbraco:Item field="PostDate" useIfEmpty="createDate" formatAsDate="true" runat="server" />
Razor View
@Umbraco.Field("PostDate", altFieldAlias: "CreateDate", formatAsDate: true)
Masterpage
<umbraco:macro alias="topNavigation" />
Razor View
@Umbraco.RenderMacro("topNavigation")
Masterpage
<umbraco:macro alias="topNavigation" nodeId="1082" name="John" />
Razor View
@Umbraco.RenderMacro("topNavigation" new{ nodeId = 1082, name="John" })
Masterpage
<asp:textbox id="tb_member" runat="server" />
Razor View
@Html.TextBoxFor(model => model.MemberId)
Or with some styling and a placeholder:
@Html.TextAreaFor(model => model.MemberId,
htmlAttributes: new { @class="span9 tokeninput", placeholder="Who should be notified?" })
Or even in mostly plain HTML:
<input type="text" name="MemberId" value="@Model.MemberId"
class="span9 tokeninput" placeholder="Who should be notified?" />