{"id":928,"date":"2012-09-22T17:38:30","date_gmt":"2012-09-22T08:38:30","guid":{"rendered":"http:\/\/auctionpro.co.kr\/?p=928"},"modified":"2012-09-22T18:03:14","modified_gmt":"2012-09-22T09:03:14","slug":"c-razor-syntax-quick-reference","status":"publish","type":"post","link":"https:\/\/www.auctionpro.co.kr\/?p=928","title":{"rendered":"C# Razor Syntax Quick Reference"},"content":{"rendered":"<table>\n<tbody>\n<tr>\n<th valign=\"top\">Syntax\/Sample<\/th>\n<th valign=\"top\">Razor<\/th>\n<th valign=\"top\">Web Forms Equivalent (or remarks)<\/th>\n<\/tr>\n<tr>\n<td valign=\"top\">Code Block<\/td>\n<td valign=\"top\"><span style=\"color: #0000ff;\">@<\/span>{ int x = 123; string y = &#8220;because.&#8221;; }<\/td>\n<td valign=\"top\">&lt;% int x = 123; string y = &#8220;because.&#8221;; %&gt;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Expression (Html Encoded)<\/td>\n<td valign=\"top\">&lt;span&gt;<span style=\"color: #0000ff;\">@<\/span>model.Message&lt;\/span&gt;<\/td>\n<td valign=\"top\">&lt;span&gt;&lt;%: model.Message %&gt;&lt;\/span&gt;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Expression (Unencoded)<\/td>\n<td valign=\"top\">&lt;span&gt; <span style=\"color: #0000ff;\">@<\/span>Html.Raw(model.Message) &lt;\/span&gt;<\/td>\n<td valign=\"top\">&lt;span&gt;&lt;%= model.Message %&gt;&lt;\/span&gt;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Combining Text and markup<\/td>\n<td valign=\"top\"><span style=\"color: #0000ff;\">@<\/span>foreach(var item in items) { &lt;span&gt;<span style=\"color: #0000ff;\">@<\/span>item.Prop&lt;\/span&gt; }<\/td>\n<td valign=\"top\">&lt;% foreach(var item in items) { %&gt; &lt;span&gt;&lt;%: item.Prop %&gt;&lt;\/span&gt; &lt;% } %&gt;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Mixing code and Plain text<\/td>\n<td valign=\"top\"><span style=\"color: #0000ff;\">@\u00a0<\/span>if (foo) { &lt;text&gt;Plain Text&lt;\/text&gt; }<\/td>\n<td valign=\"top\">&lt;% if (foo) { %&gt; Plain Text &lt;% } %&gt;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Mixing code and plain text (alternate)<\/td>\n<td valign=\"top\"><span style=\"color: #0000ff;\">@<\/span>if (foo) { <span style=\"color: #0000ff;\">@<\/span>: Plain Text is <span style=\"color: #0000ff;\">@<\/span>bar }<\/td>\n<td valign=\"top\">Same as above<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Email Addresses<\/td>\n<td valign=\"top\">Hi <span style=\"color: #0000ff;\">philha@example.com<\/span><\/td>\n<td valign=\"top\">Razor recognizes basic email format and is smart enough not to treat the @ as a code delimiter<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Explicit Expression<\/td>\n<td valign=\"top\">&lt;span&gt;<span style=\"color: #0000ff;\">ISBN@(isbnNumber)<\/span>&lt;\/span&gt;<\/td>\n<td valign=\"top\">In this case, we need to be explicit about the expression by using parentheses.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Escaping the @ sign<\/td>\n<td valign=\"top\">&lt;span&gt;In Razor, you use the <span style=\"color: #0000ff;\">@@foo<\/span> to display the value of foo&lt;\/span&gt;<\/td>\n<td valign=\"top\">@@ renders a single @ in the response.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Server side Comment<\/td>\n<td valign=\"top\"><span style=\"color: #0000ff;\">@*<\/span> This is a server side multiline comment *@<\/td>\n<td valign=\"top\">&lt;%&#8211; This is a server side multiline comment &#8211;%&gt;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Calling generic method<\/td>\n<td valign=\"top\"><span style=\"color: #0000ff;\">@(MyClass.MyMethod&lt;AType&gt;())<\/span><\/td>\n<td valign=\"top\">Use parentheses to be explicit about what the expression is.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Creating a Razor Delegate<\/td>\n<td valign=\"top\"><span style=\"color: #0000ff;\">@<\/span>{ Func&lt;dynamic, object&gt; b = @&lt;strong&gt;@item&lt;\/strong&gt;; } @b(&#8220;Bold this&#8221;)<\/td>\n<td valign=\"top\">Generates a Func&lt;T, HelperResult&gt; that you can call from within Razor. See?<a title=\"Templated Razor Delegates\" href=\"http:\/\/haacked.com\/archive\/2011\/02\/27\/templated-razor-delegates.aspx\">this blog post<\/a>?for more details.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Mixing expressions and text<\/td>\n<td valign=\"top\">Hello <span style=\"color: #0000ff;\">@title. @name.<\/span><\/td>\n<td valign=\"top\">Hello &lt;%: title %&gt;. &lt;%: name %&gt;.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>note :\u00a0<a href=\"http:\/\/haacked.com\/archive\/2011\/01\/06\/razor-syntax-quick-reference.aspx\">http:\/\/haacked.com\/archive\/2011\/01\/06\/razor-syntax-quick-reference.aspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Syntax\/Sample Razor Web Forms Equivalent (or remarks) Code Block @{ int x = 123; string y = &#8220;because.&#8221;; } &lt;% int x = 123; string <a class=\"mh-excerpt-more\" href=\"https:\/\/www.auctionpro.co.kr\/?p=928\" title=\"C# Razor Syntax Quick Reference\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10],"tags":[],"class_list":["post-928","post","type-post","status-publish","format-standard","hentry","category-devc"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>C# Razor Syntax Quick Reference - AuctionPro<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.auctionpro.co.kr\/?p=928\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C# Razor Syntax Quick Reference - AuctionPro\" \/>\n<meta property=\"og:description\" content=\"Syntax\/Sample Razor Web Forms Equivalent (or remarks) Code Block @{ int x = 123; string y = &#8220;because.&#8221;; } &lt;% int x = 123; string [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.auctionpro.co.kr\/?p=928\" \/>\n<meta property=\"og:site_name\" content=\"AuctionPro\" \/>\n<meta property=\"article:published_time\" content=\"2012-09-22T08:38:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-09-22T09:03:14+00:00\" \/>\n<meta name=\"author\" content=\"golgol\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"golgol\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"2\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/?p=928#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/?p=928\"},\"author\":{\"name\":\"golgol\",\"@id\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/#\\\/schema\\\/person\\\/d3dbae599b06cd55f5b14a3e2116f7a2\"},\"headline\":\"C# Razor Syntax Quick Reference\",\"datePublished\":\"2012-09-22T08:38:30+00:00\",\"dateModified\":\"2012-09-22T09:03:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/?p=928\"},\"wordCount\":319,\"commentCount\":0,\"articleSection\":[\"[Dev]C#\"],\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.auctionpro.co.kr\\\/?p=928#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/?p=928\",\"url\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/?p=928\",\"name\":\"C# Razor Syntax Quick Reference - AuctionPro\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/#website\"},\"datePublished\":\"2012-09-22T08:38:30+00:00\",\"dateModified\":\"2012-09-22T09:03:14+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/#\\\/schema\\\/person\\\/d3dbae599b06cd55f5b14a3e2116f7a2\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/?p=928#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.auctionpro.co.kr\\\/?p=928\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/?p=928#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C# Razor Syntax Quick Reference\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/#website\",\"url\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/\",\"name\":\"AuctionPro\",\"description\":\"\uc625\uc158\ud504\ub85c\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/#\\\/schema\\\/person\\\/d3dbae599b06cd55f5b14a3e2116f7a2\",\"name\":\"golgol\",\"url\":\"https:\\\/\\\/www.auctionpro.co.kr\\\/?author=6\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C# Razor Syntax Quick Reference - AuctionPro","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.auctionpro.co.kr\/?p=928","og_locale":"ko_KR","og_type":"article","og_title":"C# Razor Syntax Quick Reference - AuctionPro","og_description":"Syntax\/Sample Razor Web Forms Equivalent (or remarks) Code Block @{ int x = 123; string y = &#8220;because.&#8221;; } &lt;% int x = 123; string [...]","og_url":"https:\/\/www.auctionpro.co.kr\/?p=928","og_site_name":"AuctionPro","article_published_time":"2012-09-22T08:38:30+00:00","article_modified_time":"2012-09-22T09:03:14+00:00","author":"golgol","twitter_card":"summary_large_image","twitter_misc":{"\uae00\uc4f4\uc774":"golgol","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"2\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.auctionpro.co.kr\/?p=928#article","isPartOf":{"@id":"https:\/\/www.auctionpro.co.kr\/?p=928"},"author":{"name":"golgol","@id":"https:\/\/www.auctionpro.co.kr\/#\/schema\/person\/d3dbae599b06cd55f5b14a3e2116f7a2"},"headline":"C# Razor Syntax Quick Reference","datePublished":"2012-09-22T08:38:30+00:00","dateModified":"2012-09-22T09:03:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.auctionpro.co.kr\/?p=928"},"wordCount":319,"commentCount":0,"articleSection":["[Dev]C#"],"inLanguage":"ko-KR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.auctionpro.co.kr\/?p=928#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.auctionpro.co.kr\/?p=928","url":"https:\/\/www.auctionpro.co.kr\/?p=928","name":"C# Razor Syntax Quick Reference - AuctionPro","isPartOf":{"@id":"https:\/\/www.auctionpro.co.kr\/#website"},"datePublished":"2012-09-22T08:38:30+00:00","dateModified":"2012-09-22T09:03:14+00:00","author":{"@id":"https:\/\/www.auctionpro.co.kr\/#\/schema\/person\/d3dbae599b06cd55f5b14a3e2116f7a2"},"breadcrumb":{"@id":"https:\/\/www.auctionpro.co.kr\/?p=928#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.auctionpro.co.kr\/?p=928"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.auctionpro.co.kr\/?p=928#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/www.auctionpro.co.kr\/"},{"@type":"ListItem","position":2,"name":"C# Razor Syntax Quick Reference"}]},{"@type":"WebSite","@id":"https:\/\/www.auctionpro.co.kr\/#website","url":"https:\/\/www.auctionpro.co.kr\/","name":"AuctionPro","description":"\uc625\uc158\ud504\ub85c","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.auctionpro.co.kr\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Person","@id":"https:\/\/www.auctionpro.co.kr\/#\/schema\/person\/d3dbae599b06cd55f5b14a3e2116f7a2","name":"golgol","url":"https:\/\/www.auctionpro.co.kr\/?author=6"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/928","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=928"}],"version-history":[{"count":0,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/928\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}