简体   繁体   中英

Merge Razor C# value with string

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM