I'm using DD4T 2 (.NET) with our web app. In SDL Web 8.5, I've got a Component with a rich text field. I add a hyperlink as a Component, using a standard External Link Component and this renders:
<a href="tcm:13-396" target="_blank">sample text</a>
This is expected. I publish the Page and verified that the broker database has the published Page content including the markup shown above.
In the web app, I used DD4T's GetPage(pageId)
method to get the Page content and I verify that the Component Presentation still has the markup as expected.
The model:
[ContentModel("general_content", true)]
public class GeneralContent : ViewModelBase
{
[RichTextField(FieldName = "body_text")]
public MvcHtmlString BodyText { get; set; }
}
The ComponentPresentationController
's action
method:
public ActionResult GeneralContent(IComponentPresentation componentPresentation)
{
var model = ViewModelFactory.BuildViewModel<GeneralContent>(componentPresentation);
return View(model);
}
Once the Component Presentation is passed to the action
method, if I check the model's BodyText
property, it seem to have stripped the anchor markup. Just a plain text "... sample text"
instead of "... <a href="http://google.co.uk" target="_blank">sample text</a>"
.
What I've tried:
- Replaced the external link Component in the rich text field with a basic hyperlink and this link renders as expected.
- Verify that the TCM URI returns the correct Component
- Increase link level to 3
- Verify that markup is included in broker db
- Verify that markup is retrieved from broker db
- Had a look at the
RichTextField
attribute fromDD4T.MVC
and theDefaultRichTextResolver.cs
fromDD4T.Core
to provide a clue as to why
Is there anything else that I may be missing? Any assistance would be much appreciated.
Update
To clarify, the "External Link Component" I mentioned meant that I created a Component using a schema I created called "External Link".
The two levels I mentioned meant that Component A was linked to Component B and Component B was added to a Page and published. I was attempting to resolve Component A which wasn't on a Page.
tcm:13-396
) you are linking to, is actually on a Page and that Page is published? From what I gather, it soulds like you are simply seeing a resolved link, to an unpublished item.