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: {
error CS1514: Unexpected symbol `public', expecting `.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With