Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler Error Message: CS1513: } expected

I am passing an object from the controller to the view. The object contains properties Name, Title and and List of Event like List Events. You can reference here (http://www.asp.net/mvc/tutorials/mvc-music-store-part-4). I am using ASP.NET MVC 3 / C# / and Scripts

@model MvcEventCalendar.Models.Category

@{
    ViewBag.Title = "Browse";
}

<h2>Browsing Category: @Model.Name</h2>

<ul>

    @foreach (var event in Model.Events)

    {
        <li>
            @event.Title
        </li>
    }
</ul>

There is a problem in lines (@foreach (var event in Model.Events)) and (@event.Title). Object Events is not visible to the Model. Similarly, title is not visible to event. The intellisense does not display anything

Compiler Error Message: CS1513: } expected

Source Error:

Line 8:  
Line 9:  <ul>
Line 10:     @foreach (var event in Model.Events)
Line 11: 
Line 12:     {
like image 361
user522767 Avatar asked Mar 22 '11 16:03

user522767


People also ask

What does error CS1514 mean in unity?

error CS1514: Unexpected symbol `public', expecting `.

What is error cs1026?

An incomplete statement was found. A common cause of this error is placing a statement, rather than an expression, within an inline expression in an ASP.NET page.


1 Answers

event is a reserve word in c#.. you could try @event (well maybe not in razor syntax now that I think about it). But seriously rename your event variable..

@foreach (var theEvent in Model.Events)
{
    <li>
        @theEvent.Title
    </li>
}

C# Keywords

like image 194
Quintin Robinson Avatar answered Sep 20 '22 20:09

Quintin Robinson