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: {
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>
}
If someone else having the problem, kindly check your HTML layout. I was getting the same error, in my case, I was missing the closing html div tag. Also ',' after span tag.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.