Oliver Spryn
Oliver Spryn

Reputation: 17348

ASP.NET MVC Razor & C# Array - Parser Error

I have an ASP.NET MVC 4 view where I have an embedded code block, like this:

@using System.Collections.Generic

@{
    PortfolioOverviewModel item = @Model.Items[0];

//Configuration
    int[] bootstrapGridValues = new int[]{12, 6, 6, 4, 4, 4};
    int deviceWidth = 800;

// More code
}

The problem is, the closing } of the array is causing IntelliSense, and the compiler to break. Instead of closing the array, it thinks that it closes the whole code block:

@using System.Collections.Generic

@{
    PortfolioOverviewModel item = @Model.Items[0];

//Configuration                    Closes the whole block  v
    int[] bootstrapGridValues = new int[]{12, 6, 6, 4, 4, 4};
    int deviceWidth = 800; // Not recognized as code

// More code
} // Not recognized as the closing brace

Why is it mixing up my braces? Is there a way I can work around this?

Note: This is the entire code block. I'm not snipping out code where I may have forgotten to close an earlier brace.

Upvotes: 1

Views: 128

Answers (1)

Reza Abolfathi
Reza Abolfathi

Reputation: 3191

remove @ from PortfolioOverviewModel item = @Model.Items[0];

it should be like following :

PortfolioOverviewModel item = Model.Items[0];

Upvotes: 1

Related Questions