Escape @ character in razor view engine

2018-12-31 14:11发布

I am creating a sample ASP.NET MVC 3 site using Razor as view engine. The razor syntax starts with @ character e.g. @RenderBody(). If I write @test on my cshtml page it gives me parse error

CS0103: The name 'test' does not exist in the current context

How do I escape '@' character?

14条回答
回忆,回不去的记忆
2楼-- · 2018-12-31 15:10

this work for me

<meta name="author" content="Alan van Buuren @("@Alan_van_Buuren")">

Or yoy can use: @@Alan_van_Buuren

:D

查看更多
骚的不知所云
3楼-- · 2018-12-31 15:11

For the question about @RazorCodePart1 @@ @RazorCodePart2, you need to the sequence:

@RazorCodePart1 @:@@ @RazorCodePart2

I know, it looks a bit odd, but it works and will get you the literal character '@' between the code blocks.

查看更多
登录 后发表回答