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 (...) {?