Reputation: 425
Umbraco Truncate doesn't seem the work for me, it constantly errors while I'm using the right code (according to the internet). I can't figure out what's wrong with it.
Error code:
Compiler Error Message: CS1502: The best overloaded method match for 'Umbraco.Web.UmbracoHelper.Truncate(System.Web.IHtmlString, int)' has some invalid arguments
Code:
<div class="grid-item col-xs-12 col-sm-6 col-md-4">
<figure>
<a href="@item.Url">
@if (@item.GetPropertyValue("image") != null)
{
<img src="@Umbraco.Media(item.GetPropertyValue("image").ToString()).Url?anchor=center&mode=crop&w=400&h=275"/>
<figcaption>
<h5>@item.GetPropertyValue("title")</h5>
<p>@Umbraco.Truncate(item.GetPropertyValue("intro"),200)</p>
</figcaption>
}
else
{
<figcaption>
<h5>@item.GetPropertyValue("title")</h5>
<p>@item.GetPropertyValue("intro")</p>
</figcaption>
}
</a>
</figure>
</div>
Not sure why <p>@Umbraco.Truncate(item.GetPropertyValue("intro"),200)</p>
does not work
Upvotes: 3
Views: 1261
Reputation: 6050
It should be
@Umbraco.Truncate(item.GetPropertyValue<string>("intro"), 200);
instead of
@Umbraco.Truncate(item.GetPropertyValue("intro"), 200);
because item.GetPropertyValue("intro")
is of type object
and you need string
as the first parameter.
Upvotes: 4