{"id":119,"date":"2013-06-18T17:18:43","date_gmt":"2013-06-18T17:18:43","guid":{"rendered":"https:\/\/www.joetannorella.com\/?p=119"},"modified":"2014-11-24T18:29:50","modified_gmt":"2014-11-24T18:29:50","slug":"some-net-bits-i-need-to-remember","status":"publish","type":"post","link":"https:\/\/www.joetannorella.com\/some-net-bits-i-need-to-remember\/","title":{"rendered":"Some .NET snippets that I need to remember"},"content":{"rendered":"

So I’m developing some front-end stuff in using .NET. Coming from a PHP, I find some of the conventions and features of .NET to be quite confusing. I’m going to update this post with some snippets I’ll likely need to use in the future:<\/p>\n

How to easily evaluate data from controller in a view<\/h3>\n

Controller code example<\/strong><\/p>\n

ViewData[“SectionParent”] = “Affiliate”;<\/p>\n

View code example<\/strong><\/p>\n

@if (ViewData[\"SectionParent\"] == \"Affiliate\") { \/\/ code here \/\/ }<\/code><\/p>\n

 <\/p>\n

How to output plain text in a view @if statement<\/h3>\n

This bit really confused me. I was trying to evaluate ViewData, where if it’s true, output some divs. It worked absolutely fine:<\/p>\n

@if (ViewData[\"SectionParent\"] == \"Affiliate\") { <div>Bla bla content and more divs<\/div> }<\/code><\/p>\n

However, doing the exact same thing with only text (no HTML markup) kept throwing an error:<\/p>\n

@if (ViewData[\"SectionParent\"] == \"Affiliate\") { Some text here }<\/code><\/p>\n

The solution is to wrap the plain text in <text><\/text> tags, and voila, it works just fine :-):<\/p>\n

@if (ViewData[\"SectionParent\"] == \"Affiliate\") { <text>Some text here<\/text> }<\/code><\/p>\n

Misc<\/h3>\n

More coming soon!<\/p>\n","protected":false},"excerpt":{"rendered":"

So I’m developing some front-end stuff in using .NET. Coming from a PHP, I find some of the conventions and features of .NET to be quite confusing. I’m going to update this post with some snippets I’ll likely need to use in the future: How to easily evaluate data from controller in a view Controller…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"yoast_head":"\nSome .NET snippets that I need to remember - JoeTannorella.com<\/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.joetannorella.com\/some-net-bits-i-need-to-remember\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Some .NET snippets that I need to remember - JoeTannorella.com\" \/>\n<meta property=\"og:description\" content=\"So I’m developing some front-end stuff in using .NET. Coming from a PHP, I find some of the conventions and features of .NET to be quite confusing. I’m going to update this post with some snippets I’ll likely need to use in the future: How to easily evaluate data from controller in a view Controller...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.joetannorella.com\/some-net-bits-i-need-to-remember\/\" \/>\n<meta property=\"og:site_name\" content=\"JoeTannorella.com\" \/>\n<meta property=\"article:published_time\" content=\"2013-06-18T17:18:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-11-24T18:29:50+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.joetannorella.com\/some-net-bits-i-need-to-remember\/\",\"url\":\"https:\/\/www.joetannorella.com\/some-net-bits-i-need-to-remember\/\",\"name\":\"Some .NET snippets that I need to remember - JoeTannorella.com\",\"isPartOf\":{\"@id\":\"https:\/\/www.joetannorella.com\/#website\"},\"datePublished\":\"2013-06-18T17:18:43+00:00\",\"dateModified\":\"2014-11-24T18:29:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.joetannorella.com\/#\/schema\/person\/84eafed4ad6cd6934b006e371c06c7ae\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.joetannorella.com\/some-net-bits-i-need-to-remember\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.joetannorella.com\/#website\",\"url\":\"https:\/\/www.joetannorella.com\/\",\"name\":\"JoeTannorella.com\",\"description\":\"Web Development | Digital Marketing | Business\/Startups | Analytics\/data\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.joetannorella.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.joetannorella.com\/#\/schema\/person\/84eafed4ad6cd6934b006e371c06c7ae\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.joetannorella.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/257001162d06da1a465f242dfa80dd7b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/257001162d06da1a465f242dfa80dd7b?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\/\/www.joetannorella.com\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Some .NET snippets that I need to remember - JoeTannorella.com","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.joetannorella.com\/some-net-bits-i-need-to-remember\/","og_locale":"en_US","og_type":"article","og_title":"Some .NET snippets that I need to remember - JoeTannorella.com","og_description":"So I’m developing some front-end stuff in using .NET. Coming from a PHP, I find some of the conventions and features of .NET to be quite confusing. I’m going to update this post with some snippets I’ll likely need to use in the future: How to easily evaluate data from controller in a view Controller...","og_url":"https:\/\/www.joetannorella.com\/some-net-bits-i-need-to-remember\/","og_site_name":"JoeTannorella.com","article_published_time":"2013-06-18T17:18:43+00:00","article_modified_time":"2014-11-24T18:29:50+00:00","author":"admin","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.joetannorella.com\/some-net-bits-i-need-to-remember\/","url":"https:\/\/www.joetannorella.com\/some-net-bits-i-need-to-remember\/","name":"Some .NET snippets that I need to remember - JoeTannorella.com","isPartOf":{"@id":"https:\/\/www.joetannorella.com\/#website"},"datePublished":"2013-06-18T17:18:43+00:00","dateModified":"2014-11-24T18:29:50+00:00","author":{"@id":"https:\/\/www.joetannorella.com\/#\/schema\/person\/84eafed4ad6cd6934b006e371c06c7ae"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.joetannorella.com\/some-net-bits-i-need-to-remember\/"]}]},{"@type":"WebSite","@id":"https:\/\/www.joetannorella.com\/#website","url":"https:\/\/www.joetannorella.com\/","name":"JoeTannorella.com","description":"Web Development | Digital Marketing | Business\/Startups | Analytics\/data","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.joetannorella.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.joetannorella.com\/#\/schema\/person\/84eafed4ad6cd6934b006e371c06c7ae","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.joetannorella.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/257001162d06da1a465f242dfa80dd7b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/257001162d06da1a465f242dfa80dd7b?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/www.joetannorella.com\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/posts\/119"}],"collection":[{"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/comments?post=119"}],"version-history":[{"count":1,"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/posts\/119\/revisions"}],"predecessor-version":[{"id":428,"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/posts\/119\/revisions\/428"}],"wp:attachment":[{"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/media?parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/categories?post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/tags?post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}