SaaS CMS has officially launched! Learn more now.

URL Property for creating Target


I need to set the Target from the URL property. Please find the below My code snippet


            Name = "Twitter URL",
            Description = "Twitter URL property",
            GroupName = TabNames.Footer,
            Order = 400)]
        public virtual Url TwitterURL { get; set; }


In the above code I need to get and assign the "Ahref" Target value.

I have also used "LinkItemCollection" for getting more LinkItems. So that I can get the Target value, like below.

 string aHref = @Html.GetFriendlyURL(null, @Footernav2.Href);
 <a href="@aHref" target="@Footernav2.Target">@Footernav2.Text</a>

The same way, I need to get the Target value for the single Link Item. Kindly help to achive this.



Jun 17, 2013 12:00

There is no way to determine a target for a single link item when you only have a property of type Url.

When you have a LinkItemCollection, you have a list of "LinkItem". A LinkItem have the attribute selected by the editor stored to Target.
For example

@foreach(LinkItem item in CurrentPage.MyLinkItemCollection)
{ <a href="@Html.GetFriendlyURL(item.Href)" @(!String.IsNullOrEmpty(item.Target) ? "target=\"" + @item.Target + "\"" : "")>@item.Text</a> }


Given that you have an Extension method on HtmlHelper called GetFriendlyURL. Note that Target is usually empty, hence you need to check the value before rendering the target-attribute or you will render target="".

If you want to render a complete link including the href, target and text without any custom html or attributes, you could use @Html.PageLink(item)

Edited, Jun 17, 2013 13:49

Thanks for your reply, Yes URL alone we can't do anything and also Epi not allows LinkItem as a separate property type.

So, is there any possible way to control the number of link item to  Linkitemcollection property ?

For example; at this scenario, the end-user needs to add only one item into the LInkitemcollection proerty.

Jun 17, 2013 14:05

You can build a validator attribute of your own, you can find some inspiration on

Personaly I think I would create a Block that contains a Url, Target and Text instead of the entire functionality you will get from the LinkItemCollection.

Jun 17, 2013 14:10
* 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.