Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater.

The following line does not compile when I put in a Razor View.

var extPropLookupNameCompania = $"extension_{SettingsHelper.ClientId.Replace("-", "")}_{"Compania"}";

However in the controller the same line works perfectly fine.

Why I cant user string interpolation on the razor views? or Maybe I need to configure something?

like image 683
Luis Valencia Avatar asked Aug 05 '15 22:08

Luis Valencia


2 Answers

You have to encapsulate it with braces like this:

EDIT: I updated because there was a missing curly.

var extPropLookupNameCompania = $("{extension_{SettingsHelper.ClientId.Replace("-", "")}_{"Compania"}");

I tried the following successfully:

 @($"It is {DateTime.Now}")
like image 199
Alexander Schmidt Avatar answered Sep 28 '22 02:09

Alexander Schmidt


If you are experiencing this error in a .NET Framework 4.5.1 project, upgrading to 4.5.2 solves the problem.

like image 23
omufeed Avatar answered Sep 28 '22 01:09

omufeed