Defining a long string in Razor

I want to define a long string and use it as a parameter in a helper class.

I have the following code that does not compile

@{
var code ="
new TEL_Helper 
{ 
   URI = "abc@domain.com", 
   Type = TEL_TelecomType.Email, 
   Use = TEL_TelecomUse.VacationHome 
}"

Html.SyntaxXML(code)
}

How to define a line that spans multiple lines and has line breaks.

and solution used:

@{
var code =@"
new TEL_Helper 
{ 
    URI = 'abc@domain.com', 
    Type = TEL_TelecomType.Email, 
    Use = TEL_TelecomUse.VacationHome 
}";

 Html.SyntaxXML(code);
 }
+5
source share
2 answers

You are looking for a standard C # string string literal.

            var code = @"
new TEL_Helper 
{ 
   URI = ""abc@domain.com"", 
   Type = TEL_TelecomType.Email, 
   Use = TEL_TelecomUse.VacationHome 
}"
+7
source

Just break the string into pieces and concatenate:

@{
    var code =
         "new TEL_Helper " +
         "{ " +
             "URI = \"abc@domain.com\"," +
         "}";
}

Remember to avoid quotation marks inside the string.

0
source

All Articles