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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:50:47+00:00 2026-05-23T16:50:47+00:00

I am using ASP.NET MVC 3. I have the following piece of code in

  • 0

I am using ASP.NET MVC 3. I have the following piece of code in my razor view:

@foreach(var c in Model.ChildCategories) {
     <div>@c.Name<br></div>
}

It works well. Why when I take away the innder div tags will it not work? This is what I tried:

@foreach(var c in Model.ChildCategories) {
     @c.Name<br>
}

I am not closing the break tag because I am using the strict doc type:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

The error that I get when I want to view the view is:

The foreach block is missing a closing "}" character.  Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.

I would prefer not to have the inner div tags because I don’t want unnecessary tags in my markup.

I also have the following piece of code:

@if (Model.ParentCategory != null)
{
     @Model.ParentCategory.Name
}
else
{
     @:N/A
}

I want to display the name of the parent category, or just the plain text N/A. Am I doing it correctly? Is it better to have the curly brackets beneath the if or next to it like if (...) {?

  • 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-23T16:50:48+00:00Added an answer on May 23, 2026 at 4:50 pm

    Check out Phil Haack’s post razor on syntax

    @foreach(var c in Model.ChildCategories) 
    {
      <text>
         @c.Name<br />
      </text>
    }
    

    but instead of using <br /> consider using <p>

    @foreach(var c in Model.ChildCategories) 
    {
      <p>
         @c.Name
      </p>
    }
    

    the last bit with @:N/A is correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following view definition in my asp.net mvc website: <% Using Ajax.BeginForm(UsrCtlChangePassword,
I am using ASP.NET MVC 3 with the razor view engine. I have the
i have the following code in c#. I'm using ASP.NET MVC 3. public override
I want to following html code using asp.net mvc 3 razor html helper: <input
I'm using Fancybox 1.3.4 with ASP.NET MVC 3. I have following link : <a
I'm using ASP.NET MVC and have a model which has an image (byte array)
I'm using ASP.NET MVC and I have a model class which represents a peice
Problem Description: I am using ASP.NET MVC and I have the following method in
Im using asp.net mvc 2.0. I have the following HtmlHelper extension: AdminOnly(HtmlHelper helper, IPrincipal
I am using ASP.NET MVC 4 with Web Api I have the following ApiController.

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.