Class BindingExtensions

Version: 21.x

Extensions to support model binding for Sitecore layout data.

Inheritance

System.Object

BindingExtensions

Namespace: Sitecore.AspNet.RenderingEngine.Binding.Extensions

Assembly: Sitecore.AspNet.RenderingEngine.dll

Syntax
public static class BindingExtensions : Object

Methods

AddSitecoreModelBinderProviders(MvcOptions)

Adds the default Sitecore model binder providers to the Microsoft.AspNetCore.Mvc.MvcOptions.

Declaration
public static void AddSitecoreModelBinderProviders(this MvcOptions options)
Parameters
TypeNameDescription
Microsoft.AspNetCore.Mvc.MvcOptionsoptionsThe Microsoft.AspNetCore.Mvc.MvcOptions to configure.

GetModelBinder(ModelBinderProviderContext)

Gets the SitecoreLayoutModelBinder for the specified binding source.

Declaration
public static BinderTypeModelBinder GetModelBinder<TSource>(this ModelBinderProviderContext context)
    where TSource : SitecoreLayoutBindingSource
Parameters
TypeNameDescription
Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderProviderContextcontextThe Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderProviderContext instance.
Returns
TypeDescription
Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BinderTypeModelBinderThe Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BinderTypeModelBinder instance.
Type Parameters
NameDescription
TSourceThe type of the binding source.

GetModelBinder<TSource, TType>(ModelBinderProviderContext)

Gets the SitecoreLayoutModelBinder for the specified model type and binding source.

Declaration
public static BinderTypeModelBinder GetModelBinder<TSource, TType>(this ModelBinderProviderContext context)
    where TSource : SitecoreLayoutBindingSource
Parameters
TypeNameDescription
Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderProviderContextcontextThe Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderProviderContext instance.
Returns
TypeDescription
Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BinderTypeModelBinderThe Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BinderTypeModelBinder instance.
Type Parameters
NameDescription
TSourceThe type of the binding source.
TTypeThe model type to bind to.
If you have suggestions for improving this article, let us know!