Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining a long string in Razor

Tags:

syntax

razor

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

I have the following code which does not compile

@{
var code ="
new TEL_Helper 
{ 
   URI = "[email protected]", 
   Type = TEL_TelecomType.Email, 
   Use = TEL_TelecomUse.VacationHome 
}"

Html.SyntaxXML(code)
}

How do I define the string that spans multiple lines and has line breaks.

and the solution I used was :

@{
var code =@"
new TEL_Helper 
{ 
    URI = '[email protected]', 
    Type = TEL_TelecomType.Email, 
    Use = TEL_TelecomUse.VacationHome 
}";

 Html.SyntaxXML(code);
 }
like image 437
BENBUN Coder Avatar asked Feb 23 '12 19:02

BENBUN Coder


1 Answers

You're looking for the standard C# verbatim string literal.

            var code = @"
new TEL_Helper 
{ 
   URI = ""[email protected]"", 
   Type = TEL_TelecomType.Email, 
   Use = TEL_TelecomUse.VacationHome 
}"
like image 192
SLaks Avatar answered Nov 15 '22 12:11

SLaks