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

时间:2012-08-27 12:59:44

标签: asp.net-mvc-3

我已经更改了服务提供商,从那时起我转到www.greptech.co.za就会收到上述错误。

服务提供商正在使用.NET 4.0,并且安装了最新的MVC3并且是最新的。

还有什么问题?我用Google搜索了,我已经完成了上述检查。服务提供商不知道还有什么问题。

我没有更改我的Web.config文件,因为它正在与我的旧服务提供商合作。

现在网站已经停机了很长时间。请任何人都可以协助

这是我的web.config文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=152368
      -->
    <configuration>
      <connectionStrings>
        <add name="MySqlServer" connectionString="Datasource=431.186.904.538;Port=3306;Database=grep;uid=user;pwd='XXXX';Allow User Variables=true;check parameters=false;logging=true" providerName="MySql.Data.MySqlClient" />
      </connectionStrings>

      <system.net>
        <mailSettings>
          <smtp deliveryMethod="Network" from="support@greptech.co.za">
            <network host="mail.greptech.co.za" userName="support@greptech.co.za" password="XXXX" port="25" />
          </smtp>
        </mailSettings>
      </system.net>

      <appSettings>
        <add key="ENV" value="PROD"/>
        <add key="webpages:Version" value="1.0.0.0" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      </appSettings>

      <system.web>
        <!--   <customErrors mode="On"/> -->
        <trace enabled="true" pageOutput="false" requestLimit="40" localOnly="false" />

        <compilation debug="true" targetFramework="4.0">

          <assemblies>
            <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          </assemblies>
        </compilation>

        <authentication mode="Forms">
          <forms loginUrl="~/Account/LogOn" timeout="2880" />
        </authentication>

       <pages>
          <namespaces>
            <add namespace="System.Web.Helpers" />
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Routing" />
            <add namespace="System.Web.WebPages" />
          </namespaces>
        </pages>
        <customErrors mode="Off"/>
      </system.web>

      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <modules runAllManagedModulesForAllRequests="true" />
            <directoryBrowse enabled="true" />
            <defaultDocument>
                <files>
                    <clear />
                    <add value="Default.htm" />
                    <add value="Default.asp" />
                    <add value="index.htm" />
                    <add value="index.html" />
                    <add value="iisstart.htm" />
                    <add value="default.aspx" />
                    <add value="index.php" />
                </files>
            </defaultDocument>
              </system.webServer>

      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>

好的,谢谢你的回复..这是〜/ Views / Web.config

    <?xml version="1.0"?>

    <configuration>
      <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
          <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
        </sectionGroup>
      </configSections>

      <system.net >
        <mailSettings>
          <smtp deliveryMethod="Network" from="support@greptech.co.za">
            <network host="mail.greptech.co.za" userName="support@greptech.co.za" password="XXXX" port="25" />
          </smtp>
        </mailSettings>
      </system.net>

      <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
          <namespaces>
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Routing" />
          </namespaces>
        </pages>
      </system.web.webPages.razor>

      <appSettings>
        <add key="webpages:Enabled" value="false" />
      </appSettings>

      <system.web>
        <httpHandlers>
          <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
        </httpHandlers>

        <!--
            Enabling request validation in view pages would cause validation to occur
            after the input has already been processed by the controller. By default
            MVC performs request validation before a controller processes the input.
            To change this behavior apply the ValidateInputAttribute to a
            controller or action.
        -->
        <pages
            validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <controls>
            <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
          </controls>
        </pages>
      </system.web>

      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />

        <handlers>
          <remove name="BlockViewHandler"/>
          <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
        </handlers>
      </system.webServer>
    </configuration>

我最终回到原来的服务提供商

2 个答案:

答案 0 :(得分:0)

我想我可能知道在查看调试输出时会发生什么 - 这部分看起来并不正确:

Line 12:   namespace ASP {
Line 13:       using System;
Line 14:       using System.Collections.Generic;
Line 15:       using System.IO;
Line 16:       using System.Linq;
Line 17:       using System.Net;
Line 18:       using System.Web;
Line 19:       using System.Web.Helpers;
Line 20:       using System.Web.Security;
Line 21:       using System.Web.UI;
Line 22:       using System.Web.WebPages;
Line 23:       using System.Web.WebPages.Html;
Line 24:       using WebMatrix.Data;
Line 25:       using WebMatrix.WebData;
Line 26:       
Line 27:       
Line 28:       public class _Page_index_cshtml : System.Web.WebPages.WebPage {

首先你的页面继承了WebPages.WebPage - 这是怎么回事?然后上面..注意缺少System.Web.Mvc?这就是为什么你也会因为缺少“BeginForm”而错误的原因。和&#39;部分&#39;方法,因为它们都是System.Web.Mvc命名空间的一部分。 这是一个新的MVC 3项目输出如何找我:

Line 12:   namespace ASP {
Line 13:       using System;
Line 14:       using System.Collections.Generic;
Line 15:       using System.IO;
Line 16:       using System.Linq;
Line 17:       using System.Net;
Line 18:       using System.Web;
Line 19:       using System.Web.Helpers;
Line 20:       using System.Web.Security;
Line 21:       using System.Web.UI;
Line 22:       using System.Web.WebPages;
Line 23:       using System.Web.Mvc;
Line 24:       using System.Web.Mvc.Ajax;
Line 25:       using System.Web.Mvc.Html;
Line 26:       using System.Web.Routing;
Line 27:       
Line 28:       
Line 29:       public class _Page_Views_Home_Index_cshtml : System.Web.Mvc.WebViewPage<dynamic> {

您在上面列出的配置完全没问题。然而,/ Views中的配置会影响视图的生成,我最好的猜测是那里有错误。这是我注意到的那一点使视图输出成为或中断(此处的命名空间直接反映在生成的代码中,类似于Problem recognizing html helpers in asp.net mvc 3 razor):

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

此时,如果您还可以添加〜/ Views / Web.config以防这不是问题,那么这似乎是一个好主意。

答案 1 :(得分:0)

结束回到原始服务提供商