November Happy Hour will be moved to Thursday December 5th.

LinkItemCollection with MVC

Vote:
 

Hi,

I've implemented a LinkItemCollection in a 7.5 Relate site and when I display the links on the page all links except external links point to the homepage of the site rather than the correct page.

I've tried rendering the links two different ways as follows but get the same result for both:

@Html.PropertyFor(m => m.CurrentPage.RelatedLinks)

@foreach(var linkItem in Model.CurrentPage.RelatedLinks)

{

      <p>@Html.PageLink(linkItem)</p>

}

I'm guessing I've missed something (this can't be a bug can it?), has anyone else encountered this?

Mark

#86557
May 23, 2014 14:48
Vote:
 
@foreach(var linkItem in Model.CurrentPage.RelatedLinks){      <p>@ <a href="@item.Href" target="@item.Target" title="@item.LinkTitleText()">@item.LinkTitleText()</a>
</p>}
#86559
May 23, 2014 15:17
Vote:
 

What Petter said, since the item linkItem is a LinkCollectionItem, not a object of type pagelink .

#86630
May 27, 2014 9:42
Vote:
 

Hi Petter and Jonas,

Thanks for your suggestion but this is still not working quite as expected.

The .Href property returns items of the format "~/link/[guid].aspx?id=[id]&epslanguage=en-GB"

Which in the source displays correctly however when I hover over the link presents:

http://localhost/pathtopage/~/link/[linkguid].aspx?id=[id]&epslanguage=en-GB which when clicked causes a 404 error. Manually removing the pathtopage value so that it is "http://localhost/link/[linkguid].aspx?id=[id]&epslanguage=en-GB" redirects to the homepage - this happens for all internal links.

So there seems to be several issues here:

  • For some reason the href has the path to the page hosting the link collection added to the start but it looks ok when viewing the source of the page
  • Each link, when correctly formatted is still redirecting to the home page even though each link is different in the source
  • I would prefer the actual link to be the friendly link e.g. http://localhost/linktopage/ rather than the internally generated link with the GUID, ID, language

Would you have any further suggestions?

Many thanks,

Mark

#86636
May 27, 2014 10:43
Vote:
 
foreach (var link in Model.Layout.MyLinkCollectionProperty)
{
<p>
<a target="@link.Target" href="@Url.ContentUrl(link.Href)">@link.Text</a>
</p>
}


Try the extension method ContentURL 

#86639
May 27, 2014 11:16
Vote:
 

Thanks Jonas, that worked perfectly!

Thanks for your help,

Mark

#86640
May 27, 2014 11:26
Vote:
 

Hi, I also have a problem with LinkItemCollection:

Let's say I have a LinkItemCollection property on my Front Page, and I have a Page_A somewhere in content tree, and I want to add a LinkItem to the Page_A with query parameter (for example, Page_A?someId=1). 

The only way I can do this is to create a "external link" with Url to my page (http://www.mysite/Page_A?someId=1) and add it to my LinkItemCollection, but when I save and publish changes in Front Page - this link is converted from external to internal, and there is no query parameter anymore.

Is it a bug or feature :)?

Thanks

#86913
Edited, Jun 04, 2014 11:22
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.