尝试使用多个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&
发布评论