Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ';BeginText';应用程序启动时的当前上下文错误中不存在_C#_Asp.net Mvc - Fatal编程技术网

C# ';BeginText';应用程序启动时的当前上下文错误中不存在

C# ';BeginText';应用程序启动时的当前上下文错误中不存在,c#,asp.net-mvc,C#,Asp.net Mvc,我在启动应用程序时遇到这个错误,以第55行为中心,该行表示: 编译器错误消息:CS0103:当前上下文中不存在名称“BeginContext” 有人能告诉我如何开始解决这个问题吗。我在任何地方都找不到任何有用的信息 Line 53: #line default Line 54: #line hidden Line 55: BeginContext(__razor_helper_writer, "~/App_Code/Content.cshtml", 120, 11, true); Line 56

我在启动应用程序时遇到这个错误,以第55行为中心,该行表示:

编译器错误消息:CS0103:当前上下文中不存在名称“BeginContext”

有人能告诉我如何开始解决这个问题吗。我在任何地方都找不到任何有用的信息

Line 53: #line default
Line 54: #line hidden
Line 55: BeginContext(__razor_helper_writer, "~/App_Code/Content.cshtml", 120, 11, true);
Line 56: 
Line 57: WriteLiteralTo(__razor_helper_writer, "    <script");
编辑(基于Bart的评论):

@使用System.Web.Mvc;
@使用Program.ExtensionMethods;
@帮助器脚本(字符串脚本名、url帮助器url)
{
}
@帮助器源脚本(字符串脚本名、url帮助器url)
{
}
@helper CSSSCcript(字符串脚本名,UrlHelper url)
{
}
@helper SourceScriptNoCache(字符串scriptName,UrlHelper url)
{
}
@helper ImageURL(字符串applicationPath、字符串imgPath)
{
字符串appPath=applicationPath!=“/”?applicationPath+“/”:“/”;
@格式(“{0}Content/Images/{1}”,appPath,imgPath);
}
@助手IFrameURL(字符串applicationPath,字符串iFramePath)
{
字符串appPath=applicationPath!=“/”?applicationPath+“/”:“/”;
@格式(“{0}{1}”,appPath,iFramePath);
}
@helper Trunc(字符串源,int strLen=50)
{
字符串结果=null;
如果(!string.IsNullOrEmpty(source)和&source.Length>strLen)
{
结果=源。子字符串(0,strLen-3)+“…”;
}
其他的
{
结果=来源;
}
@结果;
}

通过快速的谷歌搜索,我发现将配置文件更改为以下可以解决问题

<dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>

我终于拿到了。。。我不是100%确定这为什么有效,但是


按照巴特关于web配置/dll不匹配的建议,我重命名了
System.web.Mvc.dll
并重新构建了应用程序,然后它又开始工作了…

请参阅“~/app\u code/Content.cshtml”,第120行该文件中没有第120行,它只转到第43行,可能是char 120第11行。那个文件有全局剃须刀功能吗?你能发布Content.cshtml文件吗?还有哪个版本的MVC4或5?@Bart。。。我在编辑中发布了上面提到的cshtml文件。有一件事:@Url应该是大写的U,在粘贴的代码中是小写的。我认为这不是问题所在。此错误在razor编译视图时发生。删除Content.cshtml会使错误消失。删除它并开始添加方法,以查看其中是否有不符合要求的内容或任何内容会给您带来错误,在这种情况下,MVC dll和版本不匹配(视图文件夹中的web.config上的配置)以及根目录下的web.config更是一个编译问题。哪个mvc版本?检查web.config文件(两者)可能会给您一个提示。
@using System.Web.Mvc;
@using Program.ExtensionMethods;
@helper Script(string scriptName, UrlHelper url)
    {
    <script src="@url.Content("~/Scripts/" + scriptName)" type="text/javascript"></script>
}
@helper SourceScript(string scriptName, UrlHelper url)
    {
    <script src="@url.Content("~/SourceScripts/PageScripts/" + scriptName)" type="text/javascript"></script>
}
@helper CSSScript(string scriptName, UrlHelper url)
    {
    <link href="@url.Content("~/Content/" + scriptName.FindCSSFile())" rel="stylesheet" type="text/css" />
}
@helper SourceScriptNoCache(string scriptName, UrlHelper url)
    {
    <script src="@url.Content("~/SourceScripts/" + scriptName.FindFile("SourceScripts"))" type="text/javascript"></script>
}
@helper ImageURL(string applicationPath, string imgPath)
    {
        string appPath = applicationPath != "/" ? applicationPath + "/" : "/";
    @String.Format("{0}Content/Images/{1}", appPath, imgPath);
}
@helper IFrameURL(string applicationPath, string iFramePath)
    {
        string appPath = applicationPath != "/" ? applicationPath + "/" : "/";
    @String.Format("{0}{1}", appPath, iFramePath);
}
@helper Trunc(string source, int strLen = 50)
{
    string result = null;

    if(!string.IsNullOrEmpty(source) && source.Length > strLen)
    {
        result = source.Substring(0, strLen - 3) + "...";
    }
    else
    {
        result = source;
    }

    @result;
}
<dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>