1

I installed DXA example site successfuly and can edit existing Entities.

To move it further, I want to create my own Schema, Component, Page Template and display it in the DXA example site.

What I did are:

  1. Create a new Schema, named MyItem, with two plain text fields Name and Description;
  2. Create a new Component Template, exactly the same as Article Template, just renamed it to MyItem
  3. Go to the DxaWebApp, add a new folder Models under Core folder, then add a new class MyItem.cs, like below:

    [SemanticEntity(Vocab = "http://schema.org", EntityName = "ShopItem", Prefix = "s", Public = true)]
    public class MyItem : EntityModel
    {
        [SemanticProperty("s:name")]
        public string Name { get; set; }
    
        [SemanticProperty("s:description")]
        public string Description { get; set; }
    }
    
  4. Add a new file MyItem.cshtml in the folder Entity, with below code:

    @model Sdl.Web.Site.Areas.Core.Models.ShopItem
    @Model.Name
    @Model.Description
    
  5. Add a new page MyItemPage.cshtml under Page folder. Content is exactly the same as GeneralPage.cshtml

  6. Create the new Page in CMS, attach the MyItem Component to it;

After that update the Navigation and refresh setting then publish the Page. I can see the new Page name be displayed in the portal navigation, and it will load the MyItemPage.cshtml view. But there is no content be displayed in the page. Any idea why?

1 Answer 1

3

Did you read the DXA documentation? http://docs.sdl.com/LiveContent/content/en-US/SDL%20DXA-v5/GUID-51433BAF-438D-4E54-B1C2-DA390D2DE729

I have a few remarks on the points you mention:

  1. Schema.org does not define a type ShopItem, so your SemanticEntity attribute is not correct. That is not relevant for the model mapping though; implicit mapping will work if you ensure your Schema's Root Element Name is the same as your View Model class name (MyItem).
  2. Check the metadata on your CT. Normally, the MVC data (e.g. View name) is specified there and in that case CT title is not relevant.
  3. Don't forget to also register your View Model (and associated View) in the Area Registration.
  4. Remarkably minimalistic View. :-)
  5. MyItemPage.cshtml is not a Page, but a Page View (used for all Pages based on an associated Page Template). You don't have to create your own Page View right away, but if you do you have to Register it and have an associated PT.
1
  • The issue was solved. The CT metadata didn't contain the correct view name is the main reason why it couldn't work. Thanks for your help.
    – qchen01
    Commented Sep 9, 2016 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.