asp.net-mvcsitefinity

Sitefinity MVC: How to get the content item Url in Detail view of the widget template


I have a custom module with custom List and Detail widget templates. In my List widget template, I can get the content Item url with this:

@foreach (var item in Model.Items)
{
 var navigateUrl = HyperLinkHelpers.GetDetailPageUrl(item, ViewBag.DetailsPageId, ViewBag.OpenInSamePage, Model.UrlKeyPrefix); 
}

and then:

<a href="@navigateUrl">

Why can't I do the same thing in my Detail widget template and get the full content Item url? Is there a different method to get the full Url of the page in Detail widget template in MVC?

I am getting these build errors:

CS1061 'ContentDetailsViewModel' does not contain a definition for 'Items' and no accessible extension method 'Items' accepting a first argument of type 'ContentDetailsViewModel' could be found (are you missing a using directive or an assembly reference?)

CS1061 'ContentDetailsViewModel' does not contain a definition for 'UrlKeyPrefix' and no accessible extension method 'UrlKeyPrefix' accepting a first argument of type 'ContentDetailsViewModel' could be found (are you missing a using directive or an assembly reference?)

CS0103 The name 'navigateUrl' does not exist in the current context


Solution

  • So if you need to implement yourself, use one of the overloads https://github.com/Sitefinity/feather/blob/8c0bcde57c27322d48084485694f32e0714d15ee/Telerik.Sitefinity.Frontend/Mvc/Helpers/HyperLinkHelpers.cs#L32

    What's the usecase though, you need the current url, or it's like for a related content section or something?

    Sidenote, you can browse the code over here

    https://github.com/Sitefinity/feather-widgets https://github.com/Sitefinity/feather https://github.com/Sitefinity/feather-packages