1

I am working on MVC3, i have a situation where i want to do something like this:

<Div>
   @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
  ..
</div>

but razor is throwing wrong syntax error message. Could someone help me how to do this properly in side razor code.

Thank you, Rey.

1 Answer 1

6

I don't know VB, but in C# u can use

@{i = i + 1;}

or

@{ i++; /* or 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

<h1>@i</h1>

<h2>Index</h2>

@Code
    i = i + 1
End Code

<h1>@i</h1>

It works! post your markup, if u can.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
Can u 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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.