【问题标题】:Umbraco TruncateUmbraco 截断
【发布时间】:2018-06-18 14:33:53
【问题描述】:

Umbraco Truncate 似乎不适合我,当我使用正确的代码时它会不断出错(根据互联网)。我不知道它有什么问题。

错误代码:

Compiler Error Message: CS1502: The best overloaded method match for 'Umbraco.Web.UmbracoHelper.Truncate(System.Web.IHtmlString, int)' has some invalid arguments

代码:

<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>

不知道为什么&lt;p&gt;@Umbraco.Truncate(item.GetPropertyValue("intro"),200)&lt;/p&gt; 不起作用

【问题讨论】:

  • “intro”是什么数据类型?
  • Intro 有数据类型文本框。

标签: html razor umbraco truncate


【解决方案1】:

应该是

@Umbraco.Truncate(item.GetPropertyValue<string>("intro"), 200);

而不是

@Umbraco.Truncate(item.GetPropertyValue("intro"), 200);

因为item.GetPropertyValue("intro")object 类型,您需要string 作为第一个参数。

【讨论】:

  • 非常感谢!我不知道那个。
  • 是的,打败我 :-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-02
  • 2014-10-04
  • 2016-07-15
  • 2023-03-31
  • 2018-10-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多