When I put @Functions block in a separate vbhtml file in the App_Code directory using visual studio express for web 2013, the debugger doesn’t recognize the file so can’t see it. The @functions block is fine when in the same file from which I call it. I’ve
tried building the website using the debugger but that makes no difference – still can’t see it.
What am I missing? Is there some special syntax I need in the separate vbhtml file? I created a separate helpers file and that was fine but I seem to have a problem with functions. The IDE says its using Razor v2, if that’s of any relevance.
Any help greatly appreciated
I’m not clear what you mean by "can’t see file". If you place your functions or helpers file in App_Code, you have to prefix the helper or function with the name of the file – minus the extension – when you reference the function or helper in another file.
So if you create a function called Print() and you put it in a file called Functions.vbhtml and then place that in App_Code, you will call it in another vbhtml file like this:
Many thanks for your reply
I have the function in the file test78.vbhtnl in the App_Code directory. Calling a function in the @Functions code block elicits the following error:
Error 26 ‘test78′ is not declared. It may be inaccessible due to its protection level.
It doesn’t seem to recognize the file as far as I can see…..I have now run the file and the function is called correctly but I still get the same debug error if I build the website. Weirdly if I create a new empty vbhtml file and copy the functions into
it, I get no error. The only possible diffference is that the original file that is causing the error may have originally been created as a helper file (when selecting a new file option from the menu). I just got rid of the @Helpers code and replaced it with
the @Functions. Seeing these are just text files, I thought it wouldn’t make any difference. Maybe visual studio keeps a record of the types created somewhere?
Intellisense can be a little peculiar with VB sometimes. As to the different file types, there is no difference. They are both .vbhtml files, but are generated from a different template. However, I have been able to replicate the error you reported. I suspect
that’s an issue with the VB compiler/VS combination.
Good to know I not going completely mad! I guess it’s good to have this error documented out there somewhere. A little less hair may get pulled out as a result. Thanks for giving it your attention