Danieboy Danieboy - 4 months ago 8
Javascript Question

How to format text differently when longer than a specific length?

I have an API-log where every transaction is shown in a table-fashion (10 per page) and am using PrettyPrint to make the content inside the transacitons...well...prettier...

The problem is that some of the content is about 32 000 words and takes so long to prettify that it gives a timeout.

An example would be:

<strong>ResponseContent:</strong><br /> <pre class="prettyprint lang-java">@Html.DisplayFor(modelItem => resCont) </pre><br /><br />


What I want to do is to use only:

<strong>ResponseContent:</strong><br /> <pre>@Html.DisplayFor(modelItem => resCont) </pre><br /><br />


When there is more than say... 5000 words.

Is there an easy way to do this?

Answer

I found the solution.

<strong>ResponseContent:</strong><br />
@if (resCont.Length > 5000)
{
    <pre>@Html.DisplayFor(modelItem => resCont) </pre>
}
else
{
    <pre class="prettyprint lang-java">@Html.DisplayFor(modelItem => resCont) </pre>
}
<br /><br />
Comments