{"id":1205,"date":"2015-02-13T13:06:31","date_gmt":"2015-02-13T02:06:31","guid":{"rendered":"http:\/\/ntsblog.homedev.com.au\/?p=1205"},"modified":"2015-02-13T13:06:31","modified_gmt":"2015-02-13T02:06:31","slug":"mvc-razor-view-escape-character","status":"publish","type":"post","link":"https:\/\/ntsblog.homedev.com.au\/index.php\/2015\/02\/13\/mvc-razor-view-escape-character\/","title":{"rendered":"MVC Razor View escape character"},"content":{"rendered":"<div id=\"ntsbl-3197011860\" class=\"ntsbl-before-content ntsbl-entity-placement\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-6288941070289539\" crossorigin=\"anonymous\"><\/script><ins class=\"adsbygoogle\" style=\"display:inline-block;width:728px;height:90px;\" \ndata-ad-client=\"ca-pub-6288941070289539\" \ndata-ad-slot=\"9356781486\"><\/ins> \n<script> \n(adsbygoogle = window.adsbygoogle || []).push({}); \n<\/script>\n<\/div><h2>The Problem<\/h2>\n<p>You want to use your model or some code to append a variable inline with a string.<br \/>\nAssume you want to create a URL with a dynamic element like:<br \/>\n[csharp]<br \/>\nhttp:\/\/appserver-dev.domain.com<br \/>\n[\/csharp]<br \/>\nwhere -dev will be an appsetting accessed in razor from @Settings.Default.URLSuffix<\/p>\n<p>When you add the @Settings value in like so;<br \/>\n[csharp]<br \/>\nhttp:\/\/appserver@Settings.Default.URLSuffix.domain.com<br \/>\n[\/csharp]<br \/>\nit treats the @Settings.Default.URLSuffix as a text string, outputting &#8220;http:\/\/appserver@Settings.Default.URLSuffix.domain.com&#8221; not  &#8220;http:\/\/appserver-dev.domain.com&#8221; as you were hoping. What is the escape character?<\/p>\n<h2>The Solution<\/h2>\n<p>@@ is the escape sequence.. so that should be easy..<\/p>\n<p>[csharp]<br \/>\nhttp:\/\/appserver@@Settings.Default.URLSuffix.domain.com<br \/>\n[\/csharp]<br \/>\nThe problem now is it treats the .domain.com as part of the code and is not happy because a string object does not have .domain.com methods.<\/p>\n<p>[csharp]<br \/>\nhttp:\/\/appserver@@Settings.Default.URLSuffix;.domain.com<br \/>\n[\/csharp]<\/p>\n<p>Add a semi-colon to end the code and that is the problem solved.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Problem You want to use your model or some code to append a variable inline with a string. Assume you want to create a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,1],"tags":[],"class_list":["post-1205","post","type-post","status-publish","format-standard","hentry","category-mvc","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts\/1205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/comments?post=1205"}],"version-history":[{"count":0,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts\/1205\/revisions"}],"wp:attachment":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/media?parent=1205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/categories?post=1205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/tags?post=1205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}