0

I want to add the social media links to my html. My project is implemented using ASP.net MVC. When I add the below code it gives an error in this line: "@context" : "http://schema.org",

 <script type="application/ld+json">
    {
        "@context" : "http://schema.org",
        "@type" : "Organization",
        "name" : "Example",
        "url" : "https://www.example.com",
        "sameAs" : [
            "https://twitter.com/example",
        ]
    }
</script>

I added this line of code to the <head> tag in _Layout.cshtml. I checked and this code's working fine on a pure html project.

7
  • What are you expecting that code to do? As it currently stands, the braces { ... } are just creating a code block, not an object. The lines within them make no sense as it currently stands. Are you trying to create an object? If so, try var objName = { ... }; You can then useobjName for whatever your code will do next. Commented Jul 1, 2020 at 11:50
  • Thank you Tim . No it is not an object , I followed this link help.woorank.com/hc/en-us/articles/… and it said that I should use these codes for attaching my social media to my webpages . @Tim Commented Jul 1, 2020 at 12:22
  • @Tim The problem is for sure using @ before context. But I do not know what edit should I do for this Commented Jul 1, 2020 at 12:27
  • That page looks specific to people using woorank - are you using it? If so, it would be a good idea to edit your question to add more detail about what you're trying to do, as the question currently makes no reference to woorank. I don't know anything about woorank, so I'm afraid I won't be able to help. If you're not using woorank then I don't think that page will help you at all. Commented Jul 1, 2020 at 13:38
  • It is not relating to woorank or their users, I just followed the guide to help search engine understand my social media links . Is there any way I can attach my social media links to the views.cshtml? Commented Jul 1, 2020 at 14:08

1 Answer 1

1

To include that script within the HTML which is served to the client, you need to escape the @ symbol with @@.

<script type="application/ld+json">
    {
        "@@context" : "http://schema.org",
        "@@type" : "Organization",
        "name" : "Example",
        "url" : "https://www.example.com",
        "sameAs" : [
            "https://twitter.com/example"
        ]
    }
</script>

This is because razor uses @ to indicate that some C# code is about to follow (e.g. if you have a C# variable called foo, you would use it within the razor as @foo). With your original code, razor interprets it as using a variable called context and another called type, but it throws an error because it can't find those variables. Using @@ tells razor that you want the string @context rather than the variable context.

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

1 Comment

Thank you very much, and also this link has another solution that really helps thomas.vanhoutte.be/miniblog/schema-org-social-media-websites

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.