{"id":1130,"date":"2016-12-17T16:20:31","date_gmt":"2016-12-17T10:50:31","guid":{"rendered":"http:\/\/stepbystepschools.net\/?p=1130"},"modified":"2016-12-17T16:20:31","modified_gmt":"2016-12-17T10:50:31","slug":"mvc-and-angular-2-k_backingfield-problems-during-mumbai-training","status":"publish","type":"post","link":"https:\/\/www.stepbystepschools.net\/?p=1130","title":{"rendered":"MVC and Angular 2 k_backingfield problems during Mumbai training"},"content":{"rendered":"<p>This week during\u00a0<a href=\"http:\/\/stepbystepschools.net\/?page_id=868\" target=\"_blank\">MVC and Angular training in Mumbai<\/a> one of our students got a typical JSON issue when he was trying to get data from MVC WEBAPI. So he was posting using Angular 2 HTTP and from the server side MVC WebAPI was sending data back to the angular 2 client.<\/p>\n<p>Below is the error screen shot of what the student was getting. We were expecting just supplierAmount , SupplierCode and SupplierName but he was also getting k__BackingField with it.<\/p>\n<p><a href=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/12\/ash.jpg\" rel=\"attachment wp-att-1131\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-1131\" src=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/12\/ash.jpg\" alt=\"ash\" width=\"628\" height=\"357\" srcset=\"https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2016\/12\/ash.jpg 628w, https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2016\/12\/ash-300x171.jpg 300w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><\/p>\n<p>The main cause of this issue was C# auto properties. Auto properties are c# properties which are just written with set and get and without private variables. When you have auto properties then the default WEB API JSON converter adds those funny &amp; notorious backing fields.<\/p>\n<pre>publicclassSupplier\r\n{ \r\npublicstring SupplierCode { get; set; }\r\n\r\npublicstring SupplierName { get; set; }\r\n\r\npublicdecimal  SupplierAmount { get; set; }\r\n}\r\n<\/pre>\n<p>So the solution was to go and set the WEB API formatter to JsonFormatter. Once we did this everything was rocking \u263b.<\/p>\n<pre>var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;\r\n            formatter.SerializerSettings = newJsonSerializerSettings\r\n            {\r\n                Formatting = Formatting.Indented,\r\n                TypeNameHandling = TypeNameHandling.Objects,\r\n                ContractResolver = newCamelCasePropertyNamesContractResolver()\r\n            };\r\n<\/pre>\n<p>Do not miss our next\u00a0<a href=\"http:\/\/stepbystepschools.net\/?page_id=315\" target=\"_blank\">MVC core and Angular 2 Training in Mumbai<\/a> happening next week Saturday and Sunday.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week during\u00a0MVC and Angular training in Mumbai one of our students got a typical JSON issue when he was trying to get data from MVC WEBAPI. So he was posting using Angular 2 HTTP and from the server side &hellip; <a href=\"https:\/\/www.stepbystepschools.net\/?p=1130\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[91,49,3,75],"tags":[80,101,76],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MVC and Angular 2 k_backingfield problems during Mumbai training - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai<\/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.stepbystepschools.net\/?p=1130\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MVC and Angular 2 k_backingfield problems during Mumbai training - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai\" \/>\n<meta property=\"og:description\" content=\"This week during\u00a0MVC and Angular training in Mumbai one of our students got a typical JSON issue when he was trying to get data from MVC WEBAPI. So he was posting using Angular 2 HTTP and from the server side &hellip; Continue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.stepbystepschools.net\/?p=1130\" \/>\n<meta property=\"og:site_name\" content=\"Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai\" \/>\n<meta property=\"article:published_time\" content=\"2016-12-17T10:50:31+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/12\/ash.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"StepByStepSchoolsSupport\" \/>\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\":\"WebSite\",\"@id\":\"https:\/\/www.stepbystepschools.net\/#website\",\"url\":\"https:\/\/www.stepbystepschools.net\/\",\"name\":\"Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai\",\"description\":\"MVC 5\/Core, AngularJS 1.x, 2.0, 4.0, Design Pattern, Architecture, SSIS, SSAS, SSRS, Data Science, Big data, Hadoop classroom training\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.stepbystepschools.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=1130#primaryimage\",\"url\":\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/12\/ash.jpg\",\"contentUrl\":\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/12\/ash.jpg\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=1130#webpage\",\"url\":\"https:\/\/www.stepbystepschools.net\/?p=1130\",\"name\":\"MVC and Angular 2 k_backingfield problems during Mumbai training - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai\",\"isPartOf\":{\"@id\":\"https:\/\/www.stepbystepschools.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=1130#primaryimage\"},\"datePublished\":\"2016-12-17T10:50:31+00:00\",\"dateModified\":\"2016-12-17T10:50:31+00:00\",\"author\":{\"@id\":\"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/7131e4ee1c5673879e6029d14ec2f655\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=1130#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.stepbystepschools.net\/?p=1130\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=1130#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.stepbystepschools.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MVC and Angular 2 k_backingfield problems during Mumbai training\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/7131e4ee1c5673879e6029d14ec2f655\",\"name\":\"StepByStepSchoolsSupport\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cecaf2a0ee369391127b0159c266979d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cecaf2a0ee369391127b0159c266979d?s=96&d=mm&r=g\",\"caption\":\"StepByStepSchoolsSupport\"},\"url\":\"https:\/\/www.stepbystepschools.net\/?author=40\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MVC and Angular 2 k_backingfield problems during Mumbai training - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","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.stepbystepschools.net\/?p=1130","og_locale":"en_US","og_type":"article","og_title":"MVC and Angular 2 k_backingfield problems during Mumbai training - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","og_description":"This week during\u00a0MVC and Angular training in Mumbai one of our students got a typical JSON issue when he was trying to get data from MVC WEBAPI. So he was posting using Angular 2 HTTP and from the server side &hellip; Continue reading &rarr;","og_url":"https:\/\/www.stepbystepschools.net\/?p=1130","og_site_name":"Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","article_published_time":"2016-12-17T10:50:31+00:00","og_image":[{"url":"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/12\/ash.jpg"}],"twitter_card":"summary_large_image","twitter_misc":{"Written by":"StepByStepSchoolsSupport","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.stepbystepschools.net\/#website","url":"https:\/\/www.stepbystepschools.net\/","name":"Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","description":"MVC 5\/Core, AngularJS 1.x, 2.0, 4.0, Design Pattern, Architecture, SSIS, SSAS, SSRS, Data Science, Big data, Hadoop classroom training","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.stepbystepschools.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.stepbystepschools.net\/?p=1130#primaryimage","url":"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/12\/ash.jpg","contentUrl":"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2016\/12\/ash.jpg"},{"@type":"WebPage","@id":"https:\/\/www.stepbystepschools.net\/?p=1130#webpage","url":"https:\/\/www.stepbystepschools.net\/?p=1130","name":"MVC and Angular 2 k_backingfield problems during Mumbai training - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","isPartOf":{"@id":"https:\/\/www.stepbystepschools.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.stepbystepschools.net\/?p=1130#primaryimage"},"datePublished":"2016-12-17T10:50:31+00:00","dateModified":"2016-12-17T10:50:31+00:00","author":{"@id":"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/7131e4ee1c5673879e6029d14ec2f655"},"breadcrumb":{"@id":"https:\/\/www.stepbystepschools.net\/?p=1130#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.stepbystepschools.net\/?p=1130"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.stepbystepschools.net\/?p=1130#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.stepbystepschools.net\/"},{"@type":"ListItem","position":2,"name":"MVC and Angular 2 k_backingfield problems during Mumbai training"}]},{"@type":"Person","@id":"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/7131e4ee1c5673879e6029d14ec2f655","name":"StepByStepSchoolsSupport","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cecaf2a0ee369391127b0159c266979d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cecaf2a0ee369391127b0159c266979d?s=96&d=mm&r=g","caption":"StepByStepSchoolsSupport"},"url":"https:\/\/www.stepbystepschools.net\/?author=40"}]}},"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/posts\/1130"}],"collection":[{"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1130"}],"version-history":[{"count":2,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/posts\/1130\/revisions"}],"predecessor-version":[{"id":1133,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/posts\/1130\/revisions\/1133"}],"wp:attachment":[{"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}