C# 复合C1-在razor函数中访问全局数据类型

C# 复合C1-在razor函数中访问全局数据类型,c#,asp.net,razor,c1-cms,C#,Asp.net,Razor,C1 Cms,我一直在尝试实现在复合c1站点中显示全局数据类型的函数 我理解razor的基本功能是如何工作的,但它们似乎只使用本地数据。我希望创建一个razor函数,该函数可以访问和过滤(以类似于可视函数提供的DataReferenceFilter的方式)我为员工bios创建的全局数据类型,以便我可以在整个站点的多个页面上显示此信息 我已经能够创建一个视觉功能来实现这一点,但这些功能不能很好地与手动编辑的样式配合使用 这是使用直接输入函数的本地数据的函数布局: @inherits RazorFunction

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

我理解razor的基本功能是如何工作的,但它们似乎只使用本地数据。我希望创建一个razor函数,该函数可以访问和过滤(以类似于可视函数提供的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>
@继承RazorFunction
@功能{
公共重写字符串函数描述
{
获取{return“一个显示团队成员照片、姓名和小简历的人物小部件”;}
}
[FunctionParameter(Label=“Name”,Help=“在此处输入人员姓名”,DefaultValue=“Firstname Lastname”)]
公共字符串名称{get;set;}
[FunctionParameter(Label=“Position”,Help=“在此处输入人员位置”,DefaultValue=“Manager”)]
公共字符串位置{get;set;}
[FunctionParameter(Label=“Qualifications”,Help=“此处输入人员资格”,DefaultValue=“纽卡斯尔大学”)]
公共字符串限定{get;set;}
[FunctionParameter(Label=“Bio”,Help=“在此处输入个人传记snippit”,DefaultValue=“在此处输入Bio snippit”)]
公共字符串Bio{get;set;}
[FunctionParameter(Label=“Image”,Help=“选择此人员小部件要使用的图像”)]
公共数据引用ImageSource{get;set;}
}

@Name

@位置

@资格 @生物


似乎指向了正确的方向,但我不确定如何将其集成到razor函数中。

您可以在razor函数中使用数据属性。一个小例子是这样的

@{
    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>    
    }
@{
var employees=Data.Get(),其中(m=>…一些过滤器);
foreach(员工中的var员工)
{

@employee.Name

@雇员职位

@雇员资格 @员工简历

}
太好了!谢谢!对图像有什么想法吗?上面的代码只会在生成的html中产生这种效果:
/media({MediaArchive:6c639e02-6920-40ee-b6ad-17f09546502d})
而不是
/media/33f59e8e-9555-4c9e-a5bf-62c1cc2cf3ba/1576562471/People images/Firstname-Lastname.jpg
普通小部件使用DataReference和call Data.Id正确渲染图像。这与全局数据类似吗?通过[,
解决图像渲染问题。