fixing error of required non-static field

51 views Asked by At

I wanna create an article as content part for a content type in migration of my module, but when I added the article, code show me an error. here's the code:

public int UpdateFrom3() {
            ContentDefinitionManager.AlterPartDefinition(typeof(TourPart).Name, cfg => cfg.Attachable());
            ContentDefinitionService.AddPartToType("Article" + "Part", "Tour");
            ContentDefinitionManager.AlterPartDefinition(
                   "Article" + "Part",
                   b => b
                .WithField("Name", f => f
                     .OfType("InputField").WithDisplayName("Name"))
                .WithField("ImageField", f => f
                    .OfType("MediaLibraryPickerField").WithDisplayName("Images")
                    .WithSetting("MediaLibraryPickerField.Hint", "Images everywhere!").WithSetting("MediaLibraryPickerFieldSettings.Required", "False")
                    .WithSetting("MediaLibraryPickerFieldSettings.Multiple", "True"))
               .WithField("ShortDesc", f => f
                   .OfType("TextField").WithDisplayName("Short Description")
                   .WithSetting("TextFieldSettings.Flavor", "Html"))
               .WithField("LongDesc", f => f
                   .OfType("TextField").WithDisplayName("Long Description")
                   .WithSetting("TextFieldSettings.Flavor", "Html")));


            return 4;
        }

at the ContentDefinitionService.AddPartToType("Article" + "Part", "Tour"); section, code show me this: An object reference is required for non-static field what can I do to my code accept this?

1

There are 1 answers

0
mohammad97mha On BEST ANSWER

I find the answer by my self , Here's the solution:

public int UpdateFrom3()
        {
            ContentDefinitionManager.AlterPartDefinition(typeof(TourPart).Name, cfg => cfg.Attachable());

            ContentDefinitionManager.AlterTypeDefinition("Tour",
                cfg => cfg
                    .WithPart(typeof(TourPart).Name)
                    .WithPart("General")
                   );

            ContentDefinitionManager.AlterPartDefinition(
                   "General",
                   b => b
                .WithField("Name", f => f
                     .OfType("InputField").WithDisplayName("Name"))
                .WithField("NameManage", f => f
                     .OfType("InputField").WithDisplayName("NameManage"))
                .WithField("TourTypes", f => f
                     .OfType("InputField").WithDisplayName("TourTypes"))
                .WithField("TourTitle", f => f
                     .OfType("InputField").WithDisplayName("TourTitle"))
                .WithField("TourSubTitle", f => f
                     .OfType("InputField").WithDisplayName("TourSubTitle"))
                .WithField("TourSummary", f => f
                     .OfType("InputField").WithDisplayName("TourSummary"))

               .WithField("AboutTour", f => f
                   .OfType("TextField").WithDisplayName("AboutTour")
                   .WithSetting("TextFieldSettings.Flavor", "Html"))
               .WithField("Duration", f => f
                     .OfType("InputField").WithDisplayName("Duration"))

               .WithField("Cities", f => f
                   .OfType("TextField").WithDisplayName("Cities")
                   .WithSetting("TextFieldSettings.Flavor", "Html"))
               .WithField("TourIncludes", f => f
                   .OfType("TextField").WithDisplayName("TourIncludes")
                   .WithSetting("TextFieldSettings.Flavor", "Html"))
               .WithField("TourDestination", f => f
                     .OfType("InputField").WithDisplayName("TourDestination")));


            return 4;
        }