NatalieHants
NatalieHants

Reputation: 57

if condition not recognised in foreach in Razor view

Please may somebody help me with my query. I am using Web Matrix with CSHTML, a database sat behind using SQL querying and C#.

var query = "SELECT Seat_Row, Seat_No, Booked FROM Seating_Plan WHERE Seat_Row = 'A'"; 
var db = Database.Open("TheatreBooking"); 

Here I have my SQL query and my database. Then in the html <body> I have the following:

@foreach (var item in db.Query(query)) 
{ 
    if ( @item.Booked = 1 ) 
    { 
        <img src="images/unavaliable.jpg" alt="Avaliable Seat" width="30" height="30"> 
    } 
}

The problem I am having is that within my "if" statement, the @item.Booked isn't found, however, if I taken this outside the "if" statement, the @ highlights as meant to be and I can return the variable say for example nested in the <p> tags.

The error I am currently getting is "'WebMatrix.Data.DynamicRecord' does not contain a definition for 'Booked' "

Thanks

Upvotes: 2

Views: 183

Answers (1)

vandango
vandango

Reputation: 567

Removing the @ symbol should work:

if ( item.Booked = 1 ) 

Upvotes: 2

Related Questions