Skip to content

Instantly share code, notes, and snippets.

@joeriks
Last active December 28, 2015 21:29
Show Gist options
  • Select an option

  • Save joeriks/7565236 to your computer and use it in GitHub Desktop.

Select an option

Save joeriks/7565236 to your computer and use it in GitHub Desktop.
Razor recommendations for Umbraco - Mimimize anonymous logic inside the view block

Mimimize anonymous logic inside the view block:

@if (Model.TopImageOrMedia!=116 && Model.MediaArea=="" && Model.TopImage!="") {
    <img ... />
}

instead specify the intention of the pieces of your code before you use them

@{
    var showTopImageOrMedia = (Model.TopImageOrMedia==116); // dropdown const value
    var showImage = (showTopImageOrMedia && Model.MediaArea=="" && Model.TopImage!="");
}

... and only keep the simple bool variable in the view block with the html

@if(showImage) {
    <img ... />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment