0
votes

I have a .cshtml file in my App_Templates folders that builds but I have heaps of errors.

I get it saying things like:

  • The name 'Model' does not exist in the current context
  • The name 'ViewBag' does not exist in the current context
  • HtmlHelper does not contain a definition for 'TextBoxFor' and no extension method for 'TextBoxFor' accepting a...

It is strange because other cshtml files in other directories are fine and have no red line errors. I have restarted VS, restarted my PC, tried adding a few assembly lines from other questions and rebuilding. I have tried for the past day but can't fix this annoying thing.

Any helpful hints or tips would be great. If you require any specific information please let me know and i'll edit this post.

1
Does App_Templates folder contain web.config ? - Mairaj Ahmad
Nope, no web.config in there. Though there is an empty App_WebReferences folder - SharpCode
I dont think that App_Templates is a standard MVC folder. Normally, your cshtml files will reside in the Views or Views\Shared folders. @helper code packaged into cshtml files should reside in App_Code. - Georg Patscheider
Looks like that is the problem, weird though as its just a cshtml file. anyone know exactly what setting or what in MVC causes this? Would be interesting and would love to answer this question fully for future reference. - SharpCode

1 Answers

0
votes

Just wanted to close this thread for good.

The issue was as @Georg Patschieder suggested in the comments on the initial questions. The wrong folder was used and once I moved the *.cshtml files to App_Code and changed the respective references everything worked great.