Escape @ character in razor view engine

后端 未结 15 2070
梦谈多话
梦谈多话 2020-11-22 07:55

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

15条回答
  •  再見小時候
    2020-11-22 08:39

    I tried all the options above and none worked. This is what I did that worked :

    @{
        string str = @"[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$";
    }
    
    Email
    
        
    
    

    I created a string varible and passed all the RegEx pattern code into it, then used the variable in the html, and Razor was cool with it.

提交回复
热议问题