微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – Composite C1 – 访问razor函数中的全局数据类型

我一直在尝试实现在复合c1站点显示全局数据类型的函数.

我理解基本的剃刀功能如何工作,但他们似乎只使用本地数据.我期待创建一个剃刀函数,访问和过滤(以类似于可视化函数可用的DataReferenceFilter的方式)我为员工BIOS创建的全局数据类型,以便我可以在整个站点的多个页面显示此信息.

我已经能够创建一个实现此功能的视觉功能,但这些功能与手动编辑的样式不相符.

这是使用本地数据直接输入函数函数布局:

@inherits RazorFunction

    @functions {
        public override string FunctionDescription
        {
            get  { return "A people widget that diaplays a picture,name and small bio of a team member"; }
        }

    [FunctionParameter(Label = "Name",Help = "Input the persons name here",DefaultValue = "Firstname Lastname")]
    public string Name { get; set; }

    [FunctionParameter(Label = "Position",Help = "Input the persons position here",DefaultValue = "Manager")]
    public string Position { get; set; }

    [FunctionParameter(Label = "Qualifications",Help = "Input the persons qualifications here",DefaultValue = "University of Newcastle")]
    public string Qualifications { get; set; }

    [FunctionParameter(Label = "Bio",Help = "Input the persons biography snippit here",DefaultValue = "Input bio snippit here")]
    public string Bio { get; set; }

    [FunctionParameter(Label = "Image",Help = "Select the image to be used by this people widget")]
    public DataReference<IMediaFile> ImageSource { get; set; }
}

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://www.composite.net/ns/function/1.0">
    <head>
    </head>
    <body>
        <div class="peopleBox">
            <div class="peopleimg">
                <img src="~/media({@ImageSource.Data.Id})" alt="..." />
            </div>
            <p class="peoplename">@Name</p>
            <p><i>@Position</i></p>
            <h5>@Qualifications</h5>
            <div class="blockquote">
                <p>@Bio</p>
            </div>
        </div>
    </body>
</html>

The page似乎指向正确的方向,但我不确定如何将其整合到剃刀功能中.

解决方法

您可以在Razor函数中使用Data属性.一个小例子是这样的

@{
    var employees = Data.Get<INameOfYouDataType>().Where(m => ... some filter);

    foreach (var employee in employees)
    {
        <div class="peopleimg">
            <img src="~/media({@employee.Id})" alt="..." />
        </div>
        <p class="peoplename">@employee.Name</p>
        <p><i>@employee.Position</i></p>
        <h5>@employee.Qualifications</h5>
        <div class="blockquote">
            <p>@employee.Bio</p>
        </div>    
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐