---
title: "モデルのバインディング"
slug: "model-binding"
abstract: "Sitecore ASP.NETレンダリングSDKモデルバインディング機能の概要。"
---
# モデルのバインディング

> !重要以前にアプリを統合していた場合、それは旧版のASP.NETコアレンダリングSDK(バージョン22以前)を使用しています。このSDKは更新を受け取っていないため、[最新のバージョンへのアップグレード](https://doc.sitecore.com/xmc/en/developers/asp-net/latest/asp-net-core-sdk/upgrade-from-v22.html) をお勧めします。

SitecoreレンダリングエンジンはSitecoreLayoutResponseオブジェクト内のレイアウトサービスから返される主要なオブジェクト、プロパティ、フィールドに対してASP.NETモデルバインディングサポートを提供します。

モデルバインディングはIFieldReaderで行われ、大文字を区別します。モデルプロパティが属性でマッピングされていない場合、デフォルトの[ASP](https://dotnet.microsoft.com/apps/aspnet).NETモデル・ビュー・コントローラーのモデルバインディング動作が引き継ぎます。

属性、ソース、プロバイダーなどは、レンダリングエンジンライブラリのSitecore.AspNet.RenderingEngine.Binding名前空間に位置しています。

IFieldを実装するモデルプロパティは明示的な属性を必要としず、現在のコンポーネントや同名の現在のルートフィールドにバインドします。

*現在の*コンポーネント、レスポンス、またはルートは、SitecoreLayoutResponseインスタンス内の対応するオブジェクトで、HttpContextオブジェクト上のコンテキスト情報として利用可能を指します。あるリクエストに対して、現在のレスポンスとルートはすべてのコンポーネントで同じですが、プレースホルダータグヘルパーは現在のコンポーネントを動的に設定します。

レイアウトサービスの回答例:

{
 "sitecore": {
 "context": { // context
 "contextproperty1": "", // context property
 "contextproperty2": "", // context property
 "CustomContextSingleProperty": "", // custom single context property
 "CustomContextClass": {
 "customcontextprop": "", // custom context property of custom context class
 },
 },
 "route": { // route
 "routeproperty1": "", // route property
 "routeproperty2": "", // route property
 "fields": { // route fields
 "routefield1": { // route field
 "value": ""
 }
 },
 "placeholders": { // route placeholders
 "placeholder1":  // route placeholder
 {
 "componentproperty1": "", // component property
 "componentproperty2": "", // component property
 "fields": { // component fields
 "componentfield1": { // component field
 "value": ""
 }
 }
 }
 
 }
 }
 }
}

マッチングビューモデルクラス:

using Sitecore.AspNet.RenderingEngine.Binding;
using Sitecore.AspNet.RenderingEngine.Binding.Attributes;
using Sitecore.LayoutService.Client.Response;
using Sitecore.LayoutService.Client.Response.Model;
using Sitecore.LayoutService.Client.Response.Model.Fields;

public class ComplexComponent
{
 public SitecoreLayoutResponse Response {get; set;}

 public Context Context {get; set;} // Bind to "context"

 SitecoreContextProperty(Name = "contextproperty1") // Bind to "contextproperty1". Also binds custom Sitecore "Context" properties.
 public bool ContextProperty1 { get; set; }

 SitecoreContextProperty(Name = "contextproperty2") // Bind to "contextproperty2". Also binds custom Sitecore "Context" properties.
 public bool ContextProperty2 { get; set; }

 public ContextExt ContextExt { get; set; } // Bind to current Sitecore "Context" and all custom context extensions. Inherits "Context" class.

 SitecoreContext // Bind to current Sitecore "Context" and Custom Sitecore Context Properties and objects.
 public CustomContextClass CustomContextClass { get; set; }

 public Route Route {get; set;} // Bind to "route"

 SitecoreRouteProperty(Name = "routeproperty1") // Bind to "routeproperty1"
 public string RouteProperty1 { get; set; }

 SitecoreRouteProperty(Name = "routeproperty2") // Bind to "routeproperty2"
 public string RouteProperty2 { get; set; }

 SitecoreRouteFields // Bind to "route"."fields"
 public RouteFields RouteFields { get; set; }

 SitecoreRouteField(Name = "routefield1") // Bind to "routefield1"
 public TextField RouteField1 { get; set; }

 SitecoreComponentProperty(Name = "componentproperty1") // Bind to "componentproperty1"
 public string ComponentProperty1 { get; set; }

 SitecoreComponentProperty(Name = "componentproperty2") // Bind to "componentproperty2"
 public string ComponentProperty2 { get; set; }

 SitecoreComponentFields // Bind to "route"."placeholders"
 public ComponentFields ComponentFields { get; set; }

 SitecoreComponentField(Name = "componentfield1") // Bind to "componentfield1"
 public TextField ComponentField1 { get; set; }
}

public class RouteFields
{
 SitecoreRouteField(Name = "routefield1") // Bind to "routefield1"
 public TextField RouteField1 { get; set; }
}

public class ComponentFields
{
 SitecoreComponentField(Name = "componentfield1") // Bind to "componentfield1"
 public TextField ComponentField1 { get; set; }
}

// A class to extend the current Sitecore "Context" with custom properties
public class ContextExt:Context
{
 public CustomContextClass CustomContextClass { get; set; }
 public string CustomContextSingleProperty { get; set; }
}

// A class for custom Context properties
public class CustomContextClass
{
 public string CustomContextProp { get; set; }
}

> !注コンテキスト拡張の例については、「 [レイアウトサービスによって返されるコンテキストデータの拡張](https://doc.sitecore.com/xp/ja/developers/hd/19/sitecore-headless-development/extending-context-data-returned-by-the-layout-service.html "Extending context data returned by the Layout Service")」を参照してください。