using Sitecore.Mvc.Presentation
if (RenderingContext.CurrentOrNull == null)
return string.Empty;
Item
dataSource = RenderingContext.Current.Rendering.Item;
OR
Item dataSource = null;
string datasourceId = RenderingContext.Current.Rendering.DataSource;
if (Sitecore.Data.ID.IsID(datasourceId))
{
dataSource = SitecoreContext.GetItem<Item>(new Guid(datasourceId));
}
// get rendering parameters
RenderingContext.CurrentOrNull.Rendering.Parameters["Number of Fares to Display"]
============
Better for "safe" checking:
if (!string.IsNullOrEmpty(dataSource[DealListFields.DefaultBookNowOptions]))
instead of checking for null on the field and instead of doing dataSource.Fields[....]
No comments:
Post a Comment