【发布时间】:2011-08-11 14:30:13
【问题描述】:
@{int count = 0;}
@foreach (var item in Model.Resources)
{
@(count <= 3 ? Html.Raw("<div class=\"resource-row\">").ToString() : Html.Raw(""))
// some code
@(count <= 3 ? Html.Raw("</div>").ToString() : Html.Raw(""))
@(count++)
}
此代码部分无法编译,出现以下错误
Error 18 Type of conditional expression cannot be determined because there is no implicit conversion between 'string' and 'System.Web.IHtmlString' d:\Projects\IRC2011_HG\IRC2011\Views\Home\_AllResources.cshtml 21 24 IRC2011
我必须做什么?
【问题讨论】:
-
ToString 将在页面中显示 HTML 字符串。像 "".ToString() 将显示 而不是添加 div 元素。
标签: asp.net-mvc razor