SaaS CMS has officially launched! Learn more now.

Friendly url's for links created in TinyMCE


So I don't want url's like these "/link/some_weird_guid.aspx?id=XX" when I create a link using TinyMCE

but instead would like something more friendly like "/about-us/our-mission/"

I'm using the UrlResolver to achive this elsewhere in my views but how can I fix url's that are embeded inside a XHTMLString?

Can I add a DisplayTemplate to handle this somehow (LinkItem.cshtml)?

Jan 13, 2015 12:27

I think your question duplicates Rewritten action links in rich text area

Jan 13, 2015 12:39

Do you access the XHtmlString directly?

Try something like this: 

var html = Html.XhtmlString(Model).ToString();

PS: There was a bug with Html.XhtmlString that was fixed in 7.15, so If you use an older version you might have problems with blocks inside XHtmlString. Ref:

Edited, Jan 13, 2015 15:12

I'm currently on 7.13 

And I forgot to mention a crucial detail.

If I use @Html.DisplayFor(m => m.CurrentPage.MainBody)  it works fine.

But I'm displaying the XhtmlString through a "filter" helper that inserts a id attribute for every <h2> and also prepends a <ul> with a index list of links to each <h2 id="xxx">.

My method looks like this now and it works.

public static IHtmlString RenderPageIndex(this HtmlHelper htmlHelper, XhtmlString markup)
    var result = htmlHelper.XhtmlString(markup).ToString();
    //var result = markup.ToString(); // <-- Old non working code
    result = htmlHelper.AddIdsToH2(result);
    result = htmlHelper.BuildIndexList(result);
    return new MvcHtmlString(result);

Thanks @Tore!

Jan 13, 2015 15:32

You should upgrade to 7.15 (or newer) to get blocks working correctly. Ref:

Edited, Jan 13, 2015 15:39

I have same issue in Episerver 10

hyperlinks which refering to any cms page displays as /link/some_weird_guid.aspx instead of the actual link

I able to convert the url if it is located in contentreference but I don't know how can I fix the issue inside the wysiwyg editor

Mar 01, 2017 4:44


Instead of calling xhtmlString.ToString() you can call xhtmlString.ToHtmlString().

Mar 01, 2017 6:50

That's the exact thing I did but still the hyperlink inside the htmlstring created as guid and..

Mar 01, 2017 6:54

When you say created, do you mean rendered or stored in database? Because links should be stored like that.

Does the page you're linking to still exist?

Can you post your code?

Mar 01, 2017 7:00

Thanks Johan

what is happened is I've just put a text on wysiwyg  editor and create a hyperlink to one of the existing page 

when getting the wysiwyg content as HTML , the link which inside the href tag stored as the weird formatted(guid.aspx) instead of actual link address


Blurb = currentBlock.Description?.ToHtmlString(),
Mar 01, 2017 7:05

As mentioned above you need to do it through the HtmlHelper.XhtmlString(xhtmlString). Otherwise the links will not be converted and blocks will not be displayed. If you don't have access to a HtmlHelper you can do something like this:

Mar 01, 2017 10:42

Thanks  a lot

really helpful

is there any way to filter the fragment

I've found 

but did not find any document for using that
Mar 02, 2017 7:11
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.