Changing Return Types

Change types of return values in Razor functions 

By default, the function's return value type is XhtmlDocument. If you need, you can change it to other types provided they are supported in C1 CMS.

To explicitly specify the return type, use the public override property @FunctionReturnType.

Returning a string:

@inherits RazorFunction

@functions {
    public override string FunctionDescription
    {
        get  { return "A demo function that returns the string value."; }
    }
	
    public override Type FunctionReturnType {
        get { return typeof(string); }
    }
}

The time is @DateTime.Now

Returning an XElement:

@inherits RazorFunction

@functions {
    public override string FunctionDescription
    {
        get  { return "A demo function that returns the string value."; }
    }
	
    public override Type FunctionReturnType {
        get { return typeof(XElement); }
    }
}

<element example="true" datetime="@DateTime.Now" />