Try our conversational search powered by Generative AI!

Class ViewDataDictionaryExtensions

Extensions on ViewDataDictionary

Inheritance
System.Object
ViewDataDictionaryExtensions
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Web.Mvc
Assembly: EPiServer.Cms.AspNet.dll
Version: 11.20.7
Syntax
public static class ViewDataDictionaryExtensions

Methods

GetEditHints<TViewModel, TContentData>(ViewDataDictionary)

Gets a collection of edit hints, which can be used to to add connections between view data properties and content data properties. Will store the hints in the view data dictionary.

Declaration
public static EditHintCollection<TViewModel, TContentData> GetEditHints<TViewModel, TContentData>(this ViewDataDictionary viewData)
    where TContentData : IContentData
Parameters
Type Name Description
System.Web.Mvc.ViewDataDictionary viewData

The view data.

Returns
Type Description
EditHintCollection<TViewModel, TContentData>

Collection, where edit hints can be added.

Type Parameters
Name Description
TViewModel

The type of the view model.

TContentData

The type of the content data.

Remarks

It's possible to access the hints directly by using ViewData[ViewDataKeys.PropertyConnections] or ViewData[ViewDataKeys.FullRefreshProperties].

Examples
  The following example contains an controller which uses the EditHintCollection.
public class EditHintSample : PageController<EditSamplePage>
{
public ActionResult Index(EditSamplePage currentPage)
{
var model = new EditSampleViewModel
{
    Heading = currentPage.MyText,
    Body = currentPage.MainBody,
    SecondaryBody = currentPage.SecondaryBody,
    BannerUrl = currentPage.BannerUrl.ToString(),
    ShowBanner = currentPage.ShowBanner
};

// Get the edit hint collections
var editingHints = ViewData.GetEditHints<EditSampleViewModel, EditSamplePage>();

// Adds a connection between 'Heading' in view model and 'MyText' in content data.
editingHints.AddConnection(m => m.Heading, p => p.MyText);

// Add the property 'ShowBanner' to the collection of properties which requires full refresh of the page.
editingHints.AddFullRefreshFor(p => p.ShowBanner);

return View(model);
}
}

public class EditSampleViewModel
{
public string Heading { get; set; }
public string BannerUrl { get; set; }
public XhtmlString Body { get; set; }
public XhtmlString SecondaryBody { get; set; }
public virtual bool ShowBanner { get; set; }
}

[ContentType]
public class EditSampleBlock : BlockData
{
public virtual string Heading { get; set; }
public virtual XhtmlString Body { get; set; }
}

[ContentType]
public class EditSamplePage : PageData
{
public virtual string MyText { get; set; }
public virtual XhtmlString MainBody { get; set; }
public virtual XhtmlString SecondaryBody { get; set; }
public virtual Url BannerUrl { get; set; }
public virtual bool ShowBanner { get; set; }
public virtual EditSampleBlock TextBlock { get; set; }
}