Html.Raw() in ASP.NET MVC Razor view

后端 未结 3 769
醉梦人生
醉梦人生 2020-12-01 07:14
@{int count = 0;}
@foreach (var item in Model.Resources)
{
    @(count <= 3 ? Html.Raw("
").ToString() : Ht
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 07:52

    The accepted answer is correct, but I prefer:

    @{int count = 0;} 
    @foreach (var item in Model.Resources) 
    { 
        @Html.Raw(count <= 3 ? "
    " : "") // some code @Html.Raw(count <= 3 ? "
    " : "") @(count++) }

    I hope this inspires someone, even though I'm late to the party.

提交回复
热议问题