开发者

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.Titl开发者_高级运维e = "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>
}

C# Keywords


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜