0
votes

I'm developing custom News module for Orchard CMS. My NewsItem consists of few parts: TitlePart, CommonPart, BodyPart and my custom NewsPart.

When I try to create and save item, BodyPart becomes empty (other parts save correctly), and there is NULL value in DB. If I change Text column value in Common_BodyPartRecord table and then open item in editing mode, editor is empty, no value is loaded.

here is a definition of my NewsItem from migrations.cs:

        ContentDefinitionManager.AlterTypeDefinition("NewsItem", t => t
                .WithPart("NewsPart")
                .WithPart("CommonPart", p => p.WithSetting("DateEditorSettings.ShowDateEditor", "true"))
                .WithPart("TitlePart")
                .WithPart("BodyPart")
                .Draftable()                    
            );

I've tried to debug BodyPartDriverclass. When I load news item editor in admin UI, Editor() method has input BodyPart part parameter. this is the instance of BodyPart attached to my NewsItem. And here part.Text is empty string. But part.base.Record.Text = "Test" as I set in DB table directly.

I can't understand what is wrong here. Other parts like TitlePart or my NewsPart are working fine. I do not have custom code with this BodyPart in my module. Seems I missed something, but what exactly?

In addition. There is an exception in Orchard Error log:

2014-10-22 17:25:15,307 [19] Orchard.ContentManagement.Drivers.Coordinators.ContentPartDriverCoordinator - 
Default - HttpRequestValidationException thrown from IContentPartDriver by 
Orchard.Core.Common.Drivers.BodyPartDriver
http://localhost:30321/OrchardLocal/Admin/News/Edit/56
System.Web.HttpRequestValidationException (0x80004005): A potentially dangerous
Request.Form value was detected from the client (Body.Text="<p>123123123</p>").

PS: I've added [ValidateInput(false)] attribute to my NewsAdminController class as in default Orchard.Core.Contents.Controllers.AdminController. And now BodyPart saves correctly. But seems to me it is not the right way.

1

1 Answers

0
votes

Never modify the database tables or the records directly. Go through the part's properties instead.

What's happening here is that this property is saved both in the record, and in the infoset. When you modify the record and not the infoset, next time you read the property, the infoset value wins and your record value gets overwritten. This is one of many reasons why you should never touch the records yourself.