MVC Razor for loop

后端 未结 6 865
野趣味
野趣味 2021-02-13 10:29

I have this code (nested inside a form post) but am continually getting the error that it\'s missing the closing }

@for(int i=0;i< itemsCount         


        
6条回答
  •  悲&欢浪女
    2021-02-13 11:10

    you may note that for writing a code block you can write in two ways

    1. For Only a line of Block ,just like you have written in your code and this encloses just the line that contains the preceding @
    2. For Code Block using @{... } ,this gives you freedon to use Code without preceding @ except within HTML expressions .for any html/text you must precede it with @: you want to print as is,otherwise Razor will try to interpret it as code(Since @: defines content as literal for every code expression under @: you must use @ again for code)

    In your case you can do as following

    @{
        for(int i=0; i < itemsCount; i++)
        {
           @:
           @:
        }
     } 
    

提交回复
热议问题