Model.Content.Url returns the "blueprint-content" Url and not the routed values when using Findcontent
I have a custom routed controller for news item feteched from an external API based on the "Custom route with IVirtualPageController" example in the documentation:
It inherits from UmbracoPageController and IVirtualPageController
Going by the example I return a "blueprint content" like so
case nameof(news):
if (actionExecutingContext.ActionArguments.TryGetValue("itemkey", out var id))
NewsRoot = umbracoContext.Content.GetById(Guid.Parse("64f977bd-a5df-4c04-a86c-058bfb57fb10"));
else
NewsRoot = umbracoContext.Content.GetById(Guid.Parse("9883437d-8f1d-464b-9e4a-f0c72fec927a"));
return NewsRoot;
Then in the action i return a Model based on Ipublishedcontent, and in the case of a specific item, it contains a newsitem.
var news = new Newsroomitem(CurrentPage)
Model example:
public class Newsroomitem : Newsroom
{
public Newsroomitem(IPublishedContent content) : base(content) { }
public string ItemKey { get; set; }
public NewsItem NewsItem { get; set; }
}
Everything works as i expected, routing etc, except the fact that when I try to get the Url in the view (sharing links etc) and use Model.Content.Url(UrlMode...) then I get the link using the page url that i've based the route on, not the actual link of the item that appears to the user.
So every newsitem gets the same link (which is not used).
Am i doing anything wrong here or do i need to write obtain the Url in a different way when the content is routed?
Model.Content.Url returns the "blueprint-content" Url and not the routed values when using Findcontent
I have a custom routed controller for news item feteched from an external API based on the "Custom route with IVirtualPageController" example in the documentation:
It inherits from UmbracoPageController and IVirtualPageController
https://our.umbraco.com/documentation/Reference/Routing/Custom-Routes/
Going by the example I return a "blueprint content" like so
Then in the action i return a Model based on Ipublishedcontent, and in the case of a specific item, it contains a newsitem.
Model example:
Everything works as i expected, routing etc, except the fact that when I try to get the Url in the view (sharing links etc) and use Model.Content.Url(UrlMode...) then I get the link using the page url that i've based the route on, not the actual link of the item that appears to the user.
So every newsitem gets the same link (which is not used).
Am i doing anything wrong here or do i need to write obtain the Url in a different way when the content is routed?
Kind regards Martin
is working on a reply...