Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:01:38+00:00 2026-06-13T22:01:38+00:00

So I have seen this done before and I completely forgot where or what

  • 0

So I have seen this done before and I completely forgot where or what the syntax is.
Help is greatly appreciated.

So I have an element I want to add an CSS style to depending on what property is filled out or not in the Umbraco CMS. I thought it involved colons (:) or something like that after the element’s tag. But not entirely sure.

I want to do something like this

 foreach(var item in @Model.myNodeList)
      if(@item.myProperty != String.Empty){
      <div class="myStyleOne">
      }
      else if(@item.myProperty == String.Empty){
      <div class="myStyleTwo">
      }
      else{
     <div class="myDefaultStyle">
      }
        <p>My content that will be inside of this div with different starting tags</p>
      </div>
 }

I know this code is not entirely correct and I am missing something. Can anyone point me in the right direction? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:01:39+00:00Added an answer on June 13, 2026 at 10:01 pm

    OK, just in case anyone else wanted to do this too. I found out what it is.

    This is the solution. It involves adding an @: sign in front of your elements’ beginning and ending tags.
    Note: took out the last else. Thanks @Brandon for that. That didn’t make sense the first time. Brandon’s way or this way works too.

     foreach(var item in @Model.myNodeList)
        if(@item.myProperty != String.Empty){
        @:<div class="myStyleOne">
        }
        else if(@item.myProperty == String.Empty){
        @:<div class="myStyleTwo">
        }
        <p>My content that will be inside of this div with different starting tags</p>
        @:</div>
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not an expert in Git, but I have seen this done before
I have seen this done before but I can't remember where I saw it.
Okay i've seen this done somewhere before where you have a function that takes
I swear I have seen this done before but can not find it now.
for (;;) { //Something to be done repeatedly } I have seen this sort
I know this can be done and i have seen it done using some
I've seen this done before on website, and I'm wondering how I would go
I've seen this done before by Mozilla Thunderbird, and most likely other email clients.
I have seen this talked about but never answered. Maybe it has and I'm
I have seen this question and its answers and they clear up some of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.