• Basics
  • Abyss
  • Web APIs
  • C# & Razor
  • .net API
  • JS & TS API

    Show / Hide Table of Contents

    Class RazorComponent

    The base class for Razor-Components in 2sxc 10+ to 2sxc 11 - deprecated now
    Provides context infos like the Dnn object, helpers like Edit and much more.

    To use this, create cshtml files like _person-list.cshtml in your app-folder. By default, they will be typed the old way - which continues to work for compatibility. We recommend to use this from now on. To do it, your code file must begin with an @inherits statement, like this:

    Tip

    We highly recommend you use @inherits Custom.Hybrid.Razor14 or @inherits Custom.Dnn.Razor12 instead

    @inherits ToSic.Sxc.Dnn.RazorComponent
    
    <h1>hello from RazorComponent</h1>
    
    Inheritance
    System.Object
    System.Web.WebPages.WebPageExecutingBase
    System.Web.WebPages.WebPageRenderingBase
    System.Web.WebPages.WebPageBase
    ToSic.Sxc.Web.RazorComponentBase
    RazorComponent
    RazorComponentCode
    Implements
    IHasCodeLog
    IDnnRazorCustomize
    IDnnDynamicCode
    IDynamicCode
    ICreateInstance
    IHasLog
    IDnnDynamicCodeAdditions
    Namespace: ToSic.Sxc.Dnn
    Assembly: ToSic.Sxc.Dnn.Razor.dll
    Syntax
    [PublicApi_Stable_ForUseInYourCode]
    public abstract class RazorComponent : RazorComponentBase, ITemplateFile, IHasCodeLog, IRazor, IHasDynamicCodeRoot, INeedsDynamicCodeRoot, IDnnRazorCustomize, IDnnDynamicCode, IDynamicCode, ICreateInstance, ICompatibilityLevel, IHasLog, IDnnDynamicCodeAdditions, IDnnRazor, IDnnRazor11

    Fields

    | Improve this Doc View Source

    NotImplementedUseCustomBase

    Declaration
    public const string NotImplementedUseCustomBase = "Use a newer base class like Custom.Hybrid.Razor12 or Custom.Dnn.Razor12 to leverage this."
    Field Value
    Type Description
    System.String

    Properties

    | Improve this Doc View Source

    App

    A fully prepared IApp object letting you access all the data and queries in the current app.

    You'll usually want to access the data, like App.Data["Categories"] or the queries App.Query["AllPosts"].

    foreach(var cat in AsList(App.Data["Categories"])) {
        @cat.Name
    }
    
    Declaration
    public IApp App { get; }
    Property Value
    Type Description
    IApp

    The current app

    | Improve this Doc View Source

    CmsContext

    The CmsContext tells you about the environment, like what page and module we're running in. It's supposed to replace the Dnn object in Razor and WebAPI code.

    Declaration
    public ICmsContext CmsContext { get; }
    Property Value
    Type Description
    ICmsContext
    Remarks

    New in v11.11

    | Improve this Doc View Source

    Code

    Declaration
    public dynamic Code { get; }
    Property Value
    Type Description
    System.Object
    | Improve this Doc View Source

    Content

    The content object of the current razor view - IF the current view has content. If the view is a list, it will return the first item. Will be null otherwise. To tell if it's the demo/default item, use IsDemoItem.

    Declaration
    public dynamic Content { get; }
    Property Value
    Type Description
    System.Object

    A IDynamicEntity object with the current content - or null.

    | Improve this Doc View Source

    Data

    The data prepared for the current Code. Usually user data which was manually added to the instance, but can also be a query.

    You'll usually want to access the "Default" stream like Data["Default"].

    foreach(var person in AsList(Data["Default"])) {
        @person.Name
    }
    
    Declaration
    public IContextData Data { get; }
    Property Value
    Type Description
    IContextData

    An IContextData which is as IDataSource.

    | Improve this Doc View Source

    Dnn

    The DNN context.

    Declaration
    public IDnnContext Dnn { get; }
    Property Value
    Type Description
    IDnnContext

    The DNN context.

    | Improve this Doc View Source

    Edit

    Helper commands to enable in-page editing functionality Use it to check if edit is enabled, generate context-json infos and provide toolbar buttons

    Declaration
    public IEditService Edit { get; }
    Property Value
    Type Description
    IEditService

    An IEditService object.

    | Improve this Doc View Source

    Header

    The header object of the current razor view, if it's a list and has a header object. If it's a list and doesn't have a header (and no default), it will return null. To tell if it's the demo/default item, use IsDemoItem.

    Declaration
    public dynamic Header { get; }
    Property Value
    Type Description
    System.Object

    A IDynamicEntity object with the current content.

    Remarks

    Introduced in 2sxc 10.10 - previously it was called ListContent, now deprecated.

    | Improve this Doc View Source

    Link

    Link helper object to create the correct links

    Declaration
    public ILinkService Link { get; }
    Property Value
    Type Description
    ILinkService

    A ILinkService object.

    | Improve this Doc View Source

    Purpose

    The purpose of the current execution. The code might be called for showing to a user, or search-indexing.

    Declaration
    [Obsolete("Shouldn't be used any more, but will continue to work for indefinitely for old base classes, not in v12. There are now better ways of doing this")]
    public Purpose Purpose { get; }
    Property Value
    Type Description
    Purpose

    The value of the current purpose.

    Methods

    | Improve this Doc View Source

    AsAdam(IEntity, String)

    Provides an Adam instance for this item and field

    Declaration
    public IFolder AsAdam(IEntity entity, string fieldName)
    Parameters
    Type Name Description
    IEntity entity

    The entity, often Content or similar

    System.String fieldName

    The field name, like "Gallery" or "Pics"

    Returns
    Type Description
    IFolder

    An Adam object for navigating the assets

    | Improve this Doc View Source

    AsAdam(IDynamicEntity, String)

    Provides an Adam instance for this item and field

    Declaration
    public IFolder AsAdam(IDynamicEntity entity, string fieldName)
    Parameters
    Type Name Description
    IDynamicEntity entity

    The entity, often Content or similar

    System.String fieldName

    The field name, like "Gallery" or "Pics"

    Returns
    Type Description
    IFolder

    An Adam object for navigating the assets

    | Improve this Doc View Source

    AsDynamic(Object)

    Convert a dynamic entity and return itself again. This is so coders don't have to worry if the original object was an IEntity or a IDynamicEntity in the first place.

    Declaration
    public dynamic AsDynamic(object dynamicEntity)
    Parameters
    Type Name Description
    System.Object dynamicEntity

    the original object

    Returns
    Type Description
    System.Object

    a dynamic object for easier coding

    | Improve this Doc View Source

    AsDynamic(String, String)

    Take a json and provide it as a dynamic object to the code

    Declaration
    public dynamic AsDynamic(string json, string fallback = "{}")
    Parameters
    Type Name Description
    System.String json

    the original json string

    System.String fallback

    Alternate string to use, if the original json can't parse. Can also be null or the word "error" if you would prefer an error to be thrown.

    Returns
    Type Description
    System.Object

    A dynamic object representing the original json. If it can't be parsed, it will parse the fallback, which by default is an empty empty dynamic object. If you provide null for the fallback, then you will get null back.

    Remarks

    Added in 2sxc 10.22.00

    | Improve this Doc View Source

    AsDynamic(IEntity)

    Wraps an entity into a IDynamicEntity

    Declaration
    public dynamic AsDynamic(IEntity entity)
    Parameters
    Type Name Description
    IEntity entity

    the original object

    Returns
    Type Description
    System.Object

    a dynamic object for easier coding

    | Improve this Doc View Source

    AsEntity(Object)

    Unwraps a dynamic entity back into the underlying IEntity

    Declaration
    public IEntity AsEntity(object dynamicEntity)
    Parameters
    Type Name Description
    System.Object dynamicEntity

    the wrapped IEntity

    Returns
    Type Description
    IEntity

    A normal IEntity

    | Improve this Doc View Source

    AsList(Object)

    Converts a list of IEntity objects into a list of IDynamicEntity objects.

    Declaration
    public IEnumerable<dynamic> AsList(object list)
    Parameters
    Type Name Description
    System.Object list

    typically a List/IEnumerable of Entities or DynamicEntities.
    Can also be a IDataSource in which case it uses the default stream.

    Returns
    Type Description
    System.Collections.Generic.IEnumerable<System.Object>

    a list of IDynamicEntity objects

    Remarks

    Added in 2sxc 10.21.00

    | Improve this Doc View Source

    CreateSource<T>(IDataSource, ILookUpEngine)

    Create a IDataSource which will process data from the given stream.

    Declaration
    public T CreateSource<T>(IDataSource inSource = null, ILookUpEngine configurationProvider = null)
        where T : IDataSource
    Parameters
    Type Name Description
    IDataSource inSource

    The data source which will be the default In of the new data-source.

    ILookUpEngine configurationProvider

    An alternate configuration provider for the DataSource

    Returns
    Type Description
    T

    A typed DataSource object

    Type Parameters
    Name Description
    T

    A data-source type - must be inherited from IDataSource

    | Improve this Doc View Source

    CreateSource<T>(IDataStream)

    Create a IDataSource which will process data from the given stream.

    Declaration
    public T CreateSource<T>(IDataStream source)
        where T : IDataSource
    Parameters
    Type Name Description
    IDataStream source

    The stream which will be the default In of the new data-source.

    Returns
    Type Description
    T

    A typed DataSource object

    Type Parameters
    Name Description
    T

    A data-source type - must be inherited from IDataSource

    | Improve this Doc View Source

    CustomizeData()

    Declaration
    [Obsolete("Shouldn't be used any more, but will continue to work for indefinitely for old base classes, not in v12. There are now better ways of doing this")]
    public virtual void CustomizeData()
    | Improve this Doc View Source

    CustomizeSearch(Dictionary<String, List<ISearchItem>>, IModule, DateTime)

    Customize how the search will process data on this page.

    Declaration
    [Obsolete("Shouldn't be used any more, but will continue to work for indefinitely for old base classes, not in v12. There are now better ways of doing this")]
    public virtual void CustomizeSearch(Dictionary<string, List<ISearchItem>> searchInfos, IModule moduleInfo, DateTime beginDate)
    Parameters
    Type Name Description
    System.Collections.Generic.Dictionary<System.String, System.Collections.Generic.List<ISearchItem>> searchInfos
    ToSic.Sxc.Context.IModule moduleInfo
    System.DateTime beginDate
    | Improve this Doc View Source

    GetService<TService>()

    Get a service from the EAV / 2sxc Dependency Injection.

    Declaration
    public TService GetService<TService>()
    Returns
    Type Description
    TService

    An object of the type or interface requested

    Type Parameters
    Name Description
    TService

    Interface (preferred) or Class which is needed

    Remarks

    Added in 2sxc 11.11

    Implements

    IHasCodeLog
    IDnnRazorCustomize
    IDnnDynamicCode
    IDynamicCode
    ICreateInstance
    IHasLog
    IDnnDynamicCodeAdditions
    • Improve this Doc
    • View Source
    Back to top Generated by DocFX