user522767 user522767 - 4 months ago 27
Ajax Question

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: {

Answer

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