How to “escape” the @ in Razor

Posted on

Question :

I’m trying to leave @ as a string. Here is the code:

hint: {
mentions: ['Pedro', 'Tiago', 'João', 'Maria'],
match: /B@(w*)$/, // Problema com @
search: function (keyword, callback) {
    callback($.grep(this.mentions, function (item) {
        return item.indexOf(keyword) == 0;
    }));
},
content: function (item) {
    return '@' + item;  // Problema com @
    }    
},

The marked lines face the problem of @.

The problem is @, it is understood as template syntax. How to leave it as a string?

    

Answer :

Ironically (or not) who escapes @ is itself @ .

Using @@ should work.

    

Leave a Reply

Your email address will not be published. Required fields are marked *