2

I just wondering how can I get an specific ContentItem in my controller.

I want to get the specific content Item and then display it's shape on my custom View.. PS: I also dont know how to get the ID of the content item should i use the ContentManager.Get(ID)

    [HttpGet]
    public ActionResult Index(string jobType, string location) {

        var vm = new SearchForJobViewModel();

        var items = new List<CustomPart>();

        // Load the WhatsAround content items
        IEnumerable<ContentItem> whatsAroundContentItems = ContentManager.Query().ForType("Custom").List();

        foreach (ContentItem contentItem in whatsAroundContentItems)
        {
            ContentItemRecord contentItemRecord = contentItem.Record;
            if (contentItem == null)
                continue;

            //CustomPart item = new CustomPart(contentItemRecord.Data);
            //items.Add(item);
        }

        //Im also planning to pass the ContentItem in the view and then render it there
        //return View("../JobSearchResults", items.Single(i => i.Name == "MyContentItem");
        return View("../JobSearchResults", vm);
    }

ADDITIONAL

    [Themed]
    [HttpGet]
    public ActionResult Index(string jobType, string location) {

        var vm = new SearchForJobViewModel();

        vm.SelectedJobType = jobType;
        vm.SelectedLocation = location;

        //query all the content items
        IEnumerable<ContentItem> items = ContentManager.Query().List();

        foreach (ContentItem contentItem in items) {

            ContentItemRecord contentItemRecord = contentItem.Record;

            if (contentItem == null)
                continue;

            if (contentItemRecord.ContentType.Name == "CustomPage") {

                // I just painfully search the contents just to get the ID of the specific content item that I want to display
                // I dont know what table where I can see the ID on the content items
                if (contentItemRecord.Id == 40) {
                    ContentItem ci = contentItem;

                    var test = ci.As<CustomPart>().Scripts; //custom part that I made

                    // the body part (raw html from the wysiwg editor)
                    // this I wil render it in my view
                    vm.Body = ci.As<BodyPart>().Text;


                }
            }
        }

        return View("../JobSearchResults", vm);
    }

JobSearchResults.cshtml

     @Html.Raw(Model.Body)

It's actually looks wierd but I'm trying something like utilizing Orchard CMS without using Orchard core (contentpart, drivers,handlers, etc)

4

1 回答 1

1

Your can refer this. http://skywalkersoftwaredevelopment.net/blog/getting-the-current-content-item-in-orchard

Or using the driver

protected override DriverResult Display(YourModulePart part, string displayType, dynamic shapeHelper){
    var title = part.As<TitlePart>();
    //here you can access the title part.
}
于 2013-08-05T18:54:48.723 回答