在App_Code文件剃刀@helper不能访问 [英] Razor @helper in App_Code cannot be accessed

查看:258
本文介绍了在App_Code文件剃刀@helper不能访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 App_Code文件,我有一个名为 FormatTelephone(串号)辅助函数 Formatter.cshtml 。我试图通过来访问它的局部视图@ Formatter.FormatTelephone(数字)。当我测试了一下,说:

In my App_code, I have a helper function called FormatTelephone(string number) in Formatter.cshtml. I tried to access it in a partial view by @Formatter.FormatTelephone(number). When I test it, it says

编译器错误信息:CS0103:名称'格式化'不会在目前的情况下存在。

Compiler Error Message: CS0103: The name 'Formatter' does not exist in the current context

什么是它的可能的原因?谢谢!

What is the likely cause of it? Thanks!

推荐答案

部署站点到另一台服务器时,我遇到了这个确切的问题。确保在App_Code / Formatter.cshtml文件实际上复制到服务器!我的错误是文件有被设置为构建行动。右键单击该文件并选择属性,然后设置生成操作为内容

I ran into this exact problem when deploying the site onto another server. Make sure the App_Code/Formatter.cshtml file is actually copied to the server! My mistake was the file has a build action that was set to 'None'. Right click on the file and select Properties, and then set the Build Action to 'Content'.

注意:

如果您还没有asp.net mvc的3/4安装确保以下的dll是在你的bin文件夹。

If you don't have asp.net mvc 3/4 installed make sure the following dlls are in your bin folder.


  • System.Web.Mvc

  • Microsoft.Web.Infrastructure

  • System.Web.Razor

  • System.Web.WebPages

  • System.Web.WebPages.Razor

  • System.Web.Mvc
  • Microsoft.Web.Infrastructure
  • System.Web.Razor
  • System.Web.WebPages
  • System.Web.WebPages.Razor

斯科特Hanselman有一个博客帖子大约什么可能导致您的问题。
BIN部署ASP.NET MVC 3剃刀到Windows服务器,而无需安装MVC

Scott Hanselman has a blog post about what might be causing your issue. BIN Deploying ASP.NET MVC 3 with Razor to a Windows Server without MVC installed

这篇关于在App_Code文件剃刀@helper不能访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆