@{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++)
}
This code part does not compile, with the following error
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
What I must I do?
Html.Raw()returnsIHtmlString, not the ordinarystring. So, you cannot write them in opposite sides of:operator. Remove that.ToString()callingBy the way, returning
IHtmlStringis the way MVC recognizes html content and does not encode it. Even if it hasn’t caused compiler errors, callingToString()would destroy meaning ofHtml.Raw()