I am an Orchard CMS beginner and I do not understand how to get and display a list of items in a view.
I've read the article Writing a ContentPart but the examples show how to use 2 properties instead of a list:
Driver
return ContentShape("Parts_Map", () => shapeHelper.Parts_Map(
Longitude: part.Longitude,
Latitude: part.Latitude));
View
<img alt="Location" border="1" src="http://maps.google.com/maps/api/staticmap?
&zoom=14
&size=256x256
&maptype=roadmap
&markers=color:blue|@Model.Latitude,@Model.Longitude
&sensor=false" />
I want to use a list of items in a view.
I've also read the article Orchard CMS Custom Widget View but i do not understand how it works, especially the following line:
var files = (IContentQuery<FilePart>)Model.Files;
Where can i find additional examples?
Is it below correct? I Use IContentManager contentManager for transfer data to view.
Driver:
public class MyModuleWidgetPartDriver : ContentPartDriver {
private readonly IContentManager contentManager;
public MyModuleWidgetPartDriver(IContentManager contentManager)
{
this.contentManager = contentManager;
}
protected override DriverResult Display(MyModuleWidgetPart part, string displayType, dynamic shapeHelper)
{
var MyModuleItems = this.contentManager.List<MyModulePart>(MyModulePart.ContentTypeName).ToArray();
// List of items
var MyModuleItemsViewModel = MyModuleItems.Select(MyModule => new MyModuleItemsViewModel
{
Title = MyModule.Title,
Html = MyModule.Html
});
return ContentShape("Parts_MyModules", () => shapeHelper.Parts_MyModules(
promo: Json.Encode(MyModuleItemsViewModel)));
}
MyModulePart:
public class MyModulePart : ContentPart
{
public const string ContentTypeName = "MyModule";
public string Title
{
get { return this.As<ITitleAspect>().Title; }
}
public string Html
{
get { return this.As<BodyPart>().Text; }
}
}
View\Parts\MyModule.cshtml:
@{
var MyModuleItems = Model.promo;
}