Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewBag.Title error

Tags:

Working against the current RC2 - the template that is generated Razor views includes:

@{     ViewBag.Title = "Details1";     Layout = "/Views/Shared/_Public.cshtml";  } 

With a red squiggly under ViewBag.Title and this compiler error:'

Error   4   One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll? c:\Visual Studio 2010\Projects\myProj\Views\Webinar\Details1.cshtml 6   2   TTSTrain.Webinars.WebEntry 

But the project builds and functions correctly. Is the error indicative of other problems that should be addressed?

like image 234
justSteve Avatar asked Jan 05 '11 14:01

justSteve


People also ask

What is ViewBag title?

ViewBag is a property – considered a dynamic object – that enables you to share values dynamically between the controller and view within ASP.NET MVC applications.

Is it good to use ViewBag?

A Viewbag (also Viewdata, Viewbag is only a wrapper around Viewdata) can be used like a bucket for your data. But this is not nice and it's harming the Mvc-Pattern! The view knows its model and should not get any data from anything else.


1 Answers

I got the same problem after I removed the targetFramework attribute from the <compilation> element in the Web.config file.

Once I restored it to

<compilation debug="true" targetFramework="4.0"> 

Everything worked fine again!

like image 122
Peter Avatar answered Sep 25 '22 20:09

Peter