How to increment local variable inside Razor Syntax, MVC3?

Up vote 0 down vote favorite share g+ share fb share tw.

I am working on MVC3, I have a situation where I want to do something like this: @Code Dim I = 1 End Code .... some where, I want to increment i's value, expect 'i' value should be incremented by 1 for subsequent use. @i = @i + 1 .. but razor is throwing wrong syntax error message. Could someone help me how to do this properly in side razor code.

Thank you, Rey. Vb.net mvc asp.net-mvc-3 razor link|improve this question edited Sep 21 '11 at 5:30 asked Sep 21 '11 at 5:18Manohar1119 92% accept rate.

I don't know VB, but in C# you can use @{i = I + 1;} UPDATE: I think in VB must be: @Code I = I + 1 End Code test it! UPDATE: I create a MVC3 app with VB and test this code: @Code ViewData("Title") = "Index" Dim I = 0 End Code @i Index @Code I = I + 1 End Code @i It works! Post your markup, if you can.

Its not working, I tred to put this code block inside my razor code and its still says razor invalid syntax. My view contains Razor code and markup. I want to increment i's value after some markup.

– Manohar Sep 21 '11 at 5:40 1 Can you put your markup here? It seems the error is not thrown from this. I create a MVC3 app with VB and test the code, and it works!

– Javad_Amiry Sep 21 '11 at 5:49 it works.. wrong razor syntax. Thanks for the answer. – Manohar Sep 21 '11 at 6:07 You are welcome :) (: – Javad_Amiry Sep 21 '11 at 6:11.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions