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 1014725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:17:32+00:00 2026-05-16T10:17:32+00:00

I have the following section of Razor code and it fails during runtime with

  • 0

I have the following section of Razor code and it fails during runtime with a compilation error:

@foreach(var stat in Model){
            <li>
                @stat.EffectiveDate.ToShortDateString() - @stat.EventType.Description <br />
                TimeTaken: 
                @if (@stat.TimeTaken.Hours > 0) {
                    @stat.TimeTaken.Hours hours
                }
                @stat.TimeTaken.Minutes minutes 
                @stat.TimeTaken.Seconds seconds.
            </li>
        }

The error is on the @stat.TimeTaken.Hours hours line

CS1002: ; expected

removing the literal hours fixes it.

I’m baffled.

EDIT:
Here’s the compilation output from the “@if” to “seconds”.

Line 180:       if (@stat.TimeTaken.Hours > 0) {
Line 181:                   
Line 182:              
Line 183:              #line default
Line 184:              #line hidden
Line 185:              
Line 186:              #line 29 "c:\documents and settings\dave\my documents\visual studio 2010\Projects\SportStats\SportStats\Views\Stats\Index.cshtml"
Line 187:  this.Write(stat.TimeTaken.Hours);
Line 188:              
Line 189:              #line default
Line 190:              #line hidden
Line 191:              
Line 192:              #line 29 "c:\documents and settings\dave\my documents\visual studio 2010\Projects\SportStats\SportStats\Views\Stats\Index.cshtml"
Line 193:                             hours
Line 194:               }
Line 195:  
Line 196:              
Line 197:              #line default
Line 198:              #line hidden
Line 199:              
Line 200:              #line 31 "c:\documents and settings\dave\my documents\visual studio 2010\Projects\SportStats\SportStats\Views\Stats\Index.cshtml"
Line 201:              this.WriteLiteral("\t\t\t\t");
Line 202:              
Line 203:              #line default
Line 204:              #line hidden
Line 205:              
Line 206:              #line 31 "c:\documents and settings\dave\my documents\visual studio 2010\Projects\SportStats\SportStats\Views\Stats\Index.cshtml"
Line 207:  this.Write(stat.TimeTaken.Minutes);
Line 208:              
Line 209:              #line default
Line 210:              #line hidden
Line 211:              
Line 212:              #line 31 "c:\documents and settings\dave\my documents\visual studio 2010\Projects\SportStats\SportStats\Views\Stats\Index.cshtml"
Line 213:              this.WriteLiteral(" minutes \r\n\t\t\t\t");
Line 214:              
Line 215:              #line default
Line 216:              #line hidden
Line 217:              
Line 218:              #line 32 "c:\documents and settings\dave\my documents\visual studio 2010\Projects\SportStats\SportStats\Views\Stats\Index.cshtml"
Line 219:  this.Write(stat.TimeTaken.Seconds);
Line 220:              
Line 221:              #line default
Line 222:              #line hidden
Line 223:              
Line 224:              #line 32 "c:\documents and settings\dave\my documents\visual studio 2010\Projects\SportStats\SportStats\Views\Stats\Index.cshtml"
Line 225:              this.WriteLiteral(" seconds.\r\n\t\t\t</li>\r\n");
  • 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-05-16T10:17:33+00:00Added an answer on May 16, 2026 at 10:17 am

    Try:

    @if (stat.TimeTaken.Hours > 0) {
        <text>@stat.TimeTaken.Hours hours</text>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code var section = new CustomConfigurationSection(); section.SectionInformation.Type = System.Configuration.NameValueFileSectionHandler; section.SectionInformation.SetRawXml(sectionXml);
I have following Code Block Which I tried to optimize in the Optimized section
I have the following section of code in an app that I am writing:
I have the following code section, designed to count how many Excel processes are
I have following models relation: class Section(models.Model): section = models.CharField(max_length=200, unique=True) name = models.CharField(max_length=200,
I have the following app.config section that I need to translate into code. I
I have following HTML code: <section class=indent-1> <!-- Section 1 --> <section> <div>Some content</div>
I have a project that has the following line in the additional includes section:
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public

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.