I have a Razor view Html.DisplayFor where I am displaying some text. Now I want to truncate the text using jQuery. I am using the jQuery code from this jQuery Truncate.
In my csHtml, I have something like follows, the BlogContent is some string that I am Binding. Of course I think I can do SubString etc in C# on the BlogContent to truncate. But I want to do it using jQuery. I have tried the below code but no luck.
@{
Layout = null;
}
<div class="blog-post-body">
<p class="p-bottom-20">@Html.DisplayFor(modelItem => item.BlogContent)</p>
</div>
@section scripts
{
<script src="~/js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="~/bootstrap/js/bootstrap.min.js"></script>
<script>
$(document).ready(function () {
$('ul.pagination > li.disabled > a').addClass('page-link');
truncateText(".p-bottom-20", 100);
});
function truncateText(selector, maxLength) {
$(selector).text((i, txt) => txt.length > maxLength ? txt.substr(0, maxLength) + "..." : txt);
};
</script>
}
I don't see any errors on the Browser Console related to this.

@section Scriptsinstead of@scripts._Layout.cshtml? Why do you add them again inside your view?