Mvc5 VS2013 errors in razor view

asp.net-mvc-5, c#, razor, visual-studio-2013

Solution

Changing to targetFramework="4.5.1" in the web.config fixed it for me.

Problem

I have an problem in Visual Studio where I am getting an error in my `MVC5` razor view on a line of code calling the ViewBag. ``` @{ ViewBag.Title = "Home Page"; } ``` The error is `one or more types required to compile a dynamic expression, are you missing a reference`. I've been searhing around for a solution. A few posts have asked me to add a reference to Microsoft.Csharp v.4.0.30319. This is done but still the problem. The other solution is to add the line ``` <compilation debug="true" targetFramework="4.0" /> ``` to the config file. This can't be done as I am targeting 4.5, So i altered it to 4.5. Still the same problem. There is also an issue with adding any lambda into the view, such as ``` @Html.LabelFor(a=>a.Property); ``` Which also causes an error: `'System.Web.Mvc.Html.LabelExtensions.LabelFor<TModel,TValue>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TValue>>, System.Collections.Generic.IDictionary<string,object>)' cannot be inferred from the usage. Try specifying the type arguments explicitly` Oddly enough though, the application does run as expected so I think this is a Visual Studio issue of some kind. Any help welcome!

Original source