Getting Field Values for a content item in a viewmodel

Topics: Customizing Orchard
Jan 14, 2013 at 10:38 AM

Hi There

I have a created a custom widget that will receive data from a custom handler that will render the custom widget\shape.

I am able to get the fields data in the view but I would like to pass all the data to the view as Json as I am going to be using Backbone to filter the data.

Here is what I currently have .

 

 protected override void BuildDisplayShape(BuildDisplayContext context)
		{
			base.BuildDisplayShape(context);

            if (context.ContentItem.ContentType == "NavigationWidget")
            {

                var VehicleRanges = _contentManager.Query<VehicleRangePart, VehicleRangePartRecord>("VehicleRange").List();

                //TODO add select statement to return Field data

                   
                

                dynamic packageDisplay = _orchard.New.NavigationWidgetInfo(
                    Ranges: VehicleRanges //TODO RETURN RANGE AND VEHICLE DATA AS JSON
                   
                );

                context.Shape.NavigationWidgetInfo = packageDisplay;
            }

View

    @foreach (var m in Model.Ranges) { var Navimage = m.ContentItem.VehicleRange.NavigationImage.Url; var Fitermage = m.ContentItem.VehicleRange.FilterImage.Url;
  • @m.Name
  • NAV IMAGE: @Navimage
  • Filter IMAGE: @Fitermage }
 
My question is how to I get to the

 

.NavigationImage.Url 
.FilterImage.Url

properties in the Handler

Thanks Stanton




Developer
Jan 14, 2013 at 11:01 AM

The same way you access these fields from the view. Just make sure you cast each content item to 'dynamic' to use the simplified dot notation syntax.

Jan 14, 2013 at 11:04 AM

Cool thanks

That was my problem I was not casting it as dynamic.