[英]How do I build up an html string to display within a div using razor mvc?
我正在使用razor mvc,我想建立一个html字符串,以便可以在div中将其显示在php中,如下所示:
$htmlstring = '';
foreach ($item as $items)
{
$htmlstring .= '<p>'.$item.'</p>';
}
<div>
<? echo $htmlstring; ?>
</div>
我将如何做剃刀MVC中的等效功能?
您可以将代码粘贴在Razor View的foreach
循环中
<div>
@foreach ( var item in Model.Items ){
<p>@item</p>
}
</div>
假设您传入的模型具有一个名为Items的属性,该属性是某种类型的Collection。
我认为您的意思是ASP .NET MVC Razor View Engine。
@{
//this should come from controller
List<string> items = new List<string>() { "one", "two", "three" };
}
<div id="theDiv">
@foreach (var v in items)
{
//no need for building a string, sense we can just output the <p>xyz</p> inside the div
<p>@v</p>
}
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.