GSDa
GSDa

Reputation: 193

ASP.NET : Add a number to local variable in view

I know the solution for this should be simple, but I can't figure it out. When I add a number (for example 2) to page variable, it actually considers it as a string and shows: instead of 3 : 1+2

@{
     var page= 1 ;  
 }


<li>@page+2</li>

Upvotes: 1

Views: 265

Answers (1)

Adriano Repetti
Adriano Repetti

Reputation: 67080

Expression must be evaluated server side so it must be enclosed in parenthesis:

<li>@(page+2)</li>

If you don't then parser will evaluate server side only first token after @, page will be replaced with its value and you'll have <li>1+2</li> HTML text (where, of course, no more evaluation will be performed).

Upvotes: 2

Related Questions