4

I have an ASP.Net MVC Portable Area project containing pure C# code, Razor views (cshtml), javascript and CSS. It's all being embedded into the output DLL for the area project.

I want to create a @helper function that can be accessed across the cshtml views in the area, and I followed Scott Gu's blog post to set this up. According to the Visual Studio intellisense and the compiler, everything was OK when I tried to access the helper like this:

@Helpers.MyMethod("myInput");

But when I tried running the application I got a runtime error stating that

"The name 'Helpers' does not exist in the current context"

I have put my Helpers.cshtml file in an App_Code folder in the root of my MVC portable area project, and set the build action to "Embedded resource" (as I need to do with the rest of my cshtml files).

I tested putting the Helpers.cshtml file in the App_Code folder of my ASP.Net MVC application project instead, and then it worked just fine, but it is not an option to have the helper in the application project, because I do not want dependencies from the area to the application.

It also works to rewrite the @helper to a @function and put it inside each of the CSHTML views, but I would like to avoid having this duplicated for each view.

So my question is why the application cannot seem to find the Helpers class when placed in the portable area project, and what I can do to be able to have razor helper functions inside my area that can be used across razor views.

Knut Marius
  • 1,588
  • 18
  • 40

0 Answers0