{"id":5,"date":"2011-02-20T13:39:05","date_gmt":"2011-02-20T11:39:05","guid":{"rendered":"http:\/\/dev.bratched.fr\/en\/?p=5"},"modified":"2011-02-20T13:39:05","modified_gmt":"2011-02-20T11:39:05","slug":"what-features-would-you-like-to-see-in-asp-net-mvc-4","status":"publish","type":"post","link":"https:\/\/bratched.com\/en\/2011\/02\/20\/what-features-would-you-like-to-see-in-asp-net-mvc-4\/","title":{"rendered":"What features would you like to see in ASP.NET MVC 4?"},"content":{"rendered":"<p>If there was a single feature I would like to see in ASP.NET MVC 4 that would be to remove\/deprecate ViewBag\/ViewData. Those two constructs lead to very ugly code in the views and should be avoided. Here are few of the things I hate about them:<\/p>\n<ul>\n<li>They are not strongly typed and you need to cast in your views in order to obtain the actual type<\/li>\n<li>They are not refactor friendly because they rely on magic strings<\/li>\n<li>They lead to brittle unit tests because of the magic strings<\/li>\n<li>They lead to spaghetti code in the views<\/li>\n<\/ul>\n<p>Here\u2019s the diff patch I would love to see applied for the ViewDataDictionary.cs class in ASP.NET MVC 4:<\/p>\n<div id=\"scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:045d431a-8990-4560-9a19-031dafa24fee\">\n<pre class=\"lang:c# decode:true\">diff --git ViewDataDictionary.cs ViewDataDictionary.cs\nindex 4c6299f..1965e3e 100644\n--- ViewDataDictionary.cs\n+++ ViewDataDictionary.cs\n@@ -95,12 +95,10 @@ namespace System.Web.Mvc {\n\n         public object this[string key] {\n             get {\n-                object value;\n-                _innerDictionary.TryGetValue(key, out value);\n-                return value;\n+                throw new Expcetion(\"Don't use ViewData\");\n             }\n             set {\n-                _innerDictionary[key] = value;\n+                throw new Expcetion(\"Don't use ViewData\");\n             }\n         }<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>If there was a single feature I would like to see in ASP.NET MVC 4 that would be to remove\/deprecate ViewBag\/ViewData. Those two constructs lead to very ugly code in the views and should be avoided. Here are few of the things I hate about them: They are not strongly typed and you need to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[263,265],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/posts\/5"}],"collection":[{"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/comments?post=5"}],"version-history":[{"count":0,"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/posts\/5\/revisions"}],"wp:attachment":[{"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/media?parent=5"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/categories?post=5"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/tags?post=5"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}