Yulia V
Yulia V

Reputation: 3559

How to make List<List<int>> *.cshtml/razor - compatible?

In my *.cshtml file, I want to have something like

@List<List<int>> exps = new List<List<int>>(){ new List<int>(){1}, new List<int>(){2}, new List<int>(){3, 4}};

(int is to be replaced by a more sophisticated type...) When I run the page that contains the line above, I get CS0305: Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments error.

Is it possible to fix the line of code above so that it works?

Upvotes: 3

Views: 7244

Answers (3)

Enterline
Enterline

Reputation: 66

The Razor engine might be getting confused. Try something like:

@{
    List<List<int>> exps = new List<List<int>>(){ new List<int>(){1}, new List<int>(){2}, new List<int>(){3, 4}};
}

Upvotes: 2

CodeCaster
CodeCaster

Reputation: 151672

Perhaps write it like this:

@{
    List<List<int>> exps = ...
}

Upvotes: 2

Andrei
Andrei

Reputation: 56716

I believe this is just incorrect razor syntax. That way it should work fine:

@{
    List<List<int>> exps = new List<List<int>>(){ new List<int>(){1}, new List<int>(){2}, new List<int>(){3, 4}};
}

The list then can be easily accessed over the view like this: @exps.

Upvotes: 9

Related Questions