MVC Razor for循环 [英] MVC Razor for loop
本文介绍了MVC Razor for循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码(嵌套在一个表单帖子中),但是不断收到这样的错误:它缺少结尾的}
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; i++){
<input type="hidden" @string.Format("name= item_name_{0} value= {1}",i,items[i].Description) >
<input type="hidden" @string.Format("name= item_name_{0} value= {1}",i,items[i].UnitPrice.ToString("c"))>
}
我盯着它看了足够长的时间了……有人可以帮忙吗?
I've been staring at it long enough...can anyone help?
推荐答案
尝试将@:
放在这样的html代码之前:
Try put @:
before your html code like this:
@for(int i=0;i< itemsCount; i++)
{
@: html code here
}
替代品:
1.用<text></text>
包装您的html代码
2.使用HtmlHelper
生成html代码
Alternatives:
1. wrap your html code with <text></text>
2. use HtmlHelper
to generate the html code
这篇关于MVC Razor for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文