MVC Razor for loop

后端 未结 6 861
野趣味
野趣味 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 10:58

    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"))           
        }
    

提交回复
热议问题