How to concatenate a partial url with @model.hyperlink

Topics: Writing modules
Dec 16, 2011 at 4:59 PM
Edited Dec 16, 2011 at 4:59 PM

I am pulling a partial hyperlink from the DB: /mkt_info/audioconf/ARCV_BadAttitudes.asp

 

I need to concatonate it with the full url htttp://www.website.com/mkt_info/audioconf/ARCV_BadAttitudes.asp

in my Razor syntax.

 

 

<a href="http://www.pryor.com@webinar.LearnMoreLink"</a>

Not sure how make this happen. Anyone have any idea?

Thaks
Oceantrain.
Dec 16, 2011 at 5:05 PM
Edited Dec 16, 2011 at 5:11 PM

Try this...

Add a @using System.IO and then this:

<a href="@Path.Combine("http://www.pryor.com", webinar.LearnMoreLink)"</a>

I did not actually test this but it should work.

Dec 16, 2011 at 5:46 PM

Not working :(

Dec 16, 2011 at 6:17 PM
Edited Dec 16, 2011 at 6:22 PM

I screwed it up...figures.  Try:

 <a href="@Path.Combine("http://www.pryor.com", webinar.LearnMoreLink)">The Link</a>

I just checked this and it works...Sorry!

Coordinator
Dec 16, 2011 at 7:50 PM

No no no no no no. Path.Combine is for file system paths, not URLs.

Dec 16, 2011 at 10:30 PM

This worked:

 

<a href="http://www.pryor.com/@webinar.LearnMoreLink" target="_blank" class="learnmore">Learn More >></a>
Dec 17, 2011 at 12:32 AM

Bertrand - True, Path.Combine should probably not be used for this but, it does work.

Oceantrain - I am glad you got it working.

Coordinator
Dec 17, 2011 at 1:19 AM

Not really: it will put backslashes in there instead of forward slashes.

Dec 17, 2011 at 1:57 AM

Hmmm....that is wierd because I put it on one of my views and it new what to do.  I think it had to do with the first parameter being recognized as a URL and it added the appropriate '/'.

Dec 17, 2011 at 2:29 AM

It's really the wrong way to do it; instead you should add @using Orchard.Mvc.Extensions, then use @Url.AbsoluteAction if it's at all an MVC controller you're linking to, otherwise use @Url.MakeAbsolute if you simply wish for an absolute url. This way if your application runs in a virtual subfolder (e.g. localhost/OrchardLocal) you will still get correct links.

Dec 17, 2011 at 3:38 PM

I agree...I went the way I did because the module (not a core Orchard module nor a Science Project one) used it.

I was wrong!  Should not have offered it as a solution.

Many apologies.