[英]implement for loop inside dropdown list razor view
im trying to implement a dropdown list inside razor view with items from for loop .我正在尝试使用 for 循环中的项目在 razor 视图中实现一个下拉列表。 i need the html results to look like我需要 html 结果看起来像
<select name="budget">
<option>--Please select --</option>
<option>Not sure</option>
<option> 1000 - 2000</option>
<option> ...</option>
<option>above 11000</option>
my code look like this :我的代码如下所示:
<select name = "budget" >
<option>--Please select --</option>
<option>Not sure</option>
@for (int j = 1000; j < 11000; j += 1000)
{
<option>
@{
("{{0}} -{{1}}", j, j + 1000);
}
</option>
}
<option>above 11000</option>
</select>
And the error im getting is: "Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
Thanks in advance我得到的错误是: "Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
提前致谢
try it:尝试一下:
<select name = "budget" >
<option>--Please select --</option>
<option>Not sure</option>
@for (int j = 1000; j < 11000; j += 1000)
{
<option>
@($"{j} -{j + 1000}" )
</option>
}
<option>above 11000</option>
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.