1

I have some value in meta tag like this

<meta property="og:image" content="/Content/images/share-image.jpg"" />

The problem is that Facebook wants tag to be like this

<meta property="og:image" content="http://www.example.com/Content/images/share-image.jpg"" />

I know in MVC how to get base URL like this @Request.Url.AbsoluteUri

The problem is when I try something like this in view

  <meta property="og:image" content="@Request.Url.AbsoluteUriContent/images/share-image.jpg"" />

I got Error, how can i merge string in view with this

@Request.Url.AbsoluteUri

and

Content/images/share-image.jpg
2
  • Try @(Request.Url.AbsoluteUri), note the brackets around the call Commented Jul 9, 2014 at 7:45
  • What about something like[email protected]+"/images/share-image.jpg"? Commented Jul 9, 2014 at 7:45

1 Answer 1

2

Try using braces around the C# statement:

<meta property="og:image" content="@(Request.Url.AbsoluteUri)Content/images/share-image.jpg" />

This will explicitly tell the Razor parser that the text inside @() is C# code.

Sign up to request clarification or add additional context in comments.

2 Comments

I moved the closing paranthesis infront of "Content"
Thanks @Serv, you beat me to it. ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.