In my App_code , I have a helper function called FormatTelephone(string number) in Formatter.cshtml . I tried to access it in partial form @Formatter.FormatTelephone(number) . When I test him, he says
App_code
FormatTelephone(string number)
Formatter.cshtml
@Formatter.FormatTelephone(number)
Compiler Error Message: CS0103: the name "Formatter" does not exist in the current context
What is the likely reason for this? Thanks!
I encountered this exact problem when deploying a site to another server. Make sure that the App_Code / Formatter.cshtml file is actually copied to the server! My mistake was that the file has a build action that is set to None . Right-click the file and select Properties, and then set Build Action to Content .
Note:
If you do not have asp.net mvc 3/4 installed, make sure the following DLLs are in your bin folder.
Scott Hanselman has a blog post about what might cause your problem. BIN Deploying ASP.NET MVC 3 Using Razor on Windows Server Without Installing MVC
In ~/App_Code/Formatter.cshtml following works for me:
~/App_Code/Formatter.cshtml
@helper FormatTelephone(string number) { <div>Formatted @number</div> }
and then in some cases:
@Formatter.FormatTelephone("123")