MVC Razor for loop

后端 未结 6 1327
小鲜肉
小鲜肉 2021-02-13 10:16

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:18

    Easiest way is to make use of HTML Helpers. Code will be clean as well (your name format for Description and UnitPrice seems to follow the same format; you may want to change it)

        @for (int i = 0; i < itemsCount; i++)
        {
            @Html.Hidden(string.Concat("ïtem_name_", i), items[i].Description)
            @Html.Hidden(string.Concat("ïtem_name_", i), items[i].UnitPrice.ToString("c"))           
        }
    

提交回复
热议问题