如何在MVC3的View文件中使用多FOR循环?(How to use multi FOR loop in a View file of MVC3?)

编程入门 行业动态 更新时间:2024-10-28 16:19:46
如何在MVC3的View文件中使用多FOR循环?(How to use multi FOR loop in a View file of MVC3?)

尝试使用多个FOR循环(for for for)时遇到问题。 错误消息是:

分析器错误消息: for块缺少结束“}”字符。 确保此块中的所有“{”字符都有匹配的“}”字符,并且没有任何“}”字符被解释为标记。

这是我的代码,问题来自第一个:(。

<table width="100%" border="1"> @for (int q = 0; q < quanList.Count; q++) { <tr> <td>@quanList[q]</td> @for (int s = 0; s < sizeList.Count; s++) { <td><input type="text" name="txtval" style="width:80px" /></td> } </tr> } </table>

非常感谢您的任何建议和想法。

我想显示一个包含动态行和列的表,已从控制器创建了两个列表,并通过ViewBag解析查看:

@{ List<string> sizeList = (List<string>)ViewBag.SizeList; List<string> quanList = (List<string>)ViewBag.QuanList;

}

I have a problem when trying to use multiple FOR loop (for in for). The error message is:

Parser Error Message: The for block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.

Here is my code, the problem come from the first for :( .

<table width="100%" border="1"> @for (int q = 0; q < quanList.Count; q++) { <tr> <td>@quanList[q]</td> @for (int s = 0; s < sizeList.Count; s++) { <td><input type="text" name="txtval" style="width:80px" /></td> } </tr> } </table>

Thank you very much for any suggestion and ideas.

I want to show a table with dynamic rows and columns, two list has been created from controller and parse to view via ViewBag:

@{ List<string> sizeList = (List<string>)ViewBag.SizeList; List<string> quanList = (List<string>)ViewBag.QuanList;

}

最满意答案

<table width="100%" border="1"> @{List<int> quanList = new List<int>(); List<int> sizeList = new List<int>(); } for (int q = 0; q < quanList.Count(); q++) { <tr> <td>@quanList[q] </td> for (int s = 0; s < sizeList.Count(); s++){ <td> <input type="text" name="txtval_@q_@s" style="width: 80px" /> </td> } </tr> } } </table>

尝试这个 :

尝试将此@q @s重命名为其他内容。 如果将它们混合起来,MVC将视为普通@ ,例如example@example.com 。

{int textFieldName = "txtval_" + q + "_" + s; <td> <input type="text" name="@textFieldName" style="width: 80px" /> </td> } <table width="100%" border="1"> @{List<int> quanList = new List<int>(); List<int> sizeList = new List<int>(); } for (int q = 0; q < quanList.Count(); q++) { <tr> <td>@quanList[q] </td> for (int s = 0; s < sizeList.Count(); s++){ <td> <input type="text" name="txtval_@q_@s" style="width: 80px" /> </td> } </tr> } } </table>

Try this :

Try renaming this @q @s to something else. If you mix them up , MVC will treat as a normal @ for example example@example.com .

{int textFieldName = "txtval_" + q + "_" + s; <td> <input type="text" name="@textFieldName" style="width: 80px" /> </td> }

更多推荐

ViewBag,width,问题,电脑培训,计算机培训,IT培训"/> <meta name="description&

本文发布于:2023-08-07 04:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1460074.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   如何在   file   View   multi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!