The name ‘ViewBag’ does not exist in the current context – Visual Studio 2015

I had this issue despite having all the correct configuration. It turned out to be some bad files in the Component Cache, preventing the Razor views from recognising ViewBag, Model, and HtmlHelpers. Deleting these files solved the problem (good versions of these files were created next time I opened Visual Studio). The files are located … Read more

MVC Razor @foreach

What is the best practice on where the logic for the @foreach should be at? Nowhere, just get rid of it. You could use editor or display templates. So for example: could perfectly fine be replaced by a display template: and then you will define the corresponding display template (if you don’t like the default … Read more