Here is how you can fix this:
1.Ensure the link provider is correctly configured: The link provider should resolve the internal link GUIDs to friendly URLs. Ensure that your LinkProvider settings in the Sitecore.config or Web.config
are correctly configured.
2.Use the RenderField helper: Instead of directly outputting the Model.Text, you should use the @Html.Sitecore().Field()
helper, which correctly resolves links and other dynamic content within RTE fields.
@model Sitecore.ExperienceForms.Mvc.Models.Fields.TextViewModel
<@Model.HtmlTag data-sc-field-key="@Model.ConditionSettings.FieldKey" class="@Model.CssClass">@Html.Sitecore().Field("Text", Model.Item)/@Model.HtmlTag
This helper method renders the content of the field named "Text" from the Model.Item.
The Field helper will process internal links, media links, and other dynamic content properly, converting link GUIDs to friendly URLs.
hope this helps!
If you don't have Model.item , You can try this code as well to resolve your internal code
@model Sitecore.ExperienceForms.Mvc.Models.Fields.TextViewModel
@using Sitecore.Links
@using System.Text.RegularExpressions
@functions {
// Function to resolve internal Sitecore links to friendly URLs
public string ResolveInternalLinks(string rawHtml)
{
if (string.IsNullOrEmpty(rawHtml))
{
return rawHtml;
}
// Pattern to find Sitecore internal links in the format sitecore://{GUID}
var linkPattern = new Regex(@"href=[""']sitecore://([^""']+)[""']", RegexOptions.IgnoreCase);
return linkPattern.Replace(rawHtml, match =>
{
var linkId = match.Groups[1].Value; // Extract the GUID from the match
var item = Sitecore.Context.Database.GetItem(linkId); // Get the item using the GUID
if (item != null)
{
var url = LinkManager.GetItemUrl(item); // Resolve the item to a friendly URL
return $"href=\"{url}\""; // Replace the link with the friendly URL
}
return match.Value; // Return the original match if the item is not found
});
}
}
@{
// Use the helper function to resolve links in the Model.Text
var resolvedText = ResolveInternalLinks(Model.Text);
}
<@Model.HtmlTag data-sc-field-key="@Model.ConditionSettings.FieldKey" class="@Model.CssClass">
@Html.Raw(resolvedText)
</@Model.HtmlTag>
Hope this helps!