item.GetProperty("bodytext").Value Umbraco
本文关键字:quot Value Umbraco bodytext item GetProperty | 更新日期: 2023-09-27 17:50:43
你好,我有一个问题,从我的Umbraco博客页面收集一个对象,特别是裁剪它
@foreach (var item in Model.Content.Children.Where("visible==true"))
{
var BodyTextToCrop = item.GetProperty("bodytext").Value.ToString();
<a href="@item.Url">@item.Name</a><br />
@Umbraco.Truncate(BodyTextToCrop, 2, true)
}
将语句改为:
@foreach (var item in Model.Content.Children.Where(x => x.IsVisible()))
{
var BodyTextToCrop = item.GetProperty("bodytext").Value.ToString();
<a href="@item.Url">@item.Name</a><br />
@Umbraco.Truncate(BodyTextToCrop, 2, true)
}
看起来你的where子句正在使用类型和模型的动态访问。在您的情况下,内容可以是强类型的。
看一下查询- MVC页面上的代码片段:
//dynamic access
@CurrentPage.Children.Where("Visible")
//strongly typed access
@Model.Content.Children.Where(x => x.IsVisible())