Cybercrux

Everything is achievable through technology

razor syntax

Important  Umbraco CMS Razor syntax for copy paste

Master page 

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

RenderBody();

Sections; 

in Master Layout

 <title>@RenderSection(“title”, required: false)</title>

in View

@section title{
@ViewBag.Title
}

Content Page

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = “master.cshtml”;
}

Show Page Name

@CurrentPage.Name

Load All content inside a Content: used to show all product in products page

@foreach (var child in Model.Content.Children)
{
Html.RenderPartial(child.DocumentTypeAlias, child);
}

Render Bundle:

In Bundle.cs

bundles.Add(new ScriptBundle(“~/bundles/bootstrap”).Include(
“~/Scripts/bootstrap*”,
“~/Scripts/bootbox.min.js”));

in view

@Styles.Render(“~/bundles/bootstrap”)

Render Partial view;  User control 

@ Html.RenderPartial(“partialfilename”);

RenderBody; for master pages

@RenderBody()

Render Macro; external user control added by developer

@Umbraco.RenderMacro(“macroname-from-developer-section “)

Umbraco Field; Document type generic property in settings

for string type:

@Umbraco.Field(“fieldname”)

for image type :

@{
if (CurrentPage.HasValue(“image”)){
var dynamicMediaItem = Umbraco.Media(CurrentPage.image);
<img src=”@dynamicMediaItem.umbracoFile” alt=”@dynamicMediaItem.Name”/>
}
}

All image in a Folder by id;1097 is test id

@using umbraco.MacroEngines
<ul>
@{
List<DynamicNode> imagelist = new DynamicNode(1097).Children.Items;
foreach(dynamic image in imagelist)
{
<li><img src=”@image.umbracoFile” width=”200px” height=”100px” /></li>
}
}
</ul>

Navigation Partialview;

<ul class=”menu”>
<li class=”@(CurrentPage.Url == “/” ? “active” : null)”><a href=”/”>About</a></li>

@foreach (var item in CurrentPage.AncestorsOrSelf(1).First().Children.Where(“UmbracoNaviHide == false”))
{
<li class=”@(CurrentPage.Id == item.Id ? “active” : null)”><a href=”@item.Url.Substring(0, @item.Url.Length-1)”>@item.Name</a></li>
}</ul>

Droupdown with selected

var selectQ ="SELECT StatusName, StatusID FROM MyStatusTable";
List<SelectListItem> statusdropdownlistdata =newList<SelectListItem>();
bool isSelected =false;foreach(var item in db.Query(selectQ)){
    isSelected =false;if(item.StatusName=="Completed"){
        isSelected =true;}
    statusdropdownlistdata.Add(newSelectListItem{Text= item.StatusName,Value= item.StatusID.ToString(),Selected= isSelected
    });}

@Html.DropDownList("StatusTypes", statusdropdownlistdata)

//

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s