“名称"HTML"在当前上下文中不存在"在MVC 3视图 [英] "The name 'HTML' does not exist in the current context" in MVC 3 Views

查看:83
本文介绍了“名称"HTML"在当前上下文中不存在"在MVC 3视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用"MVC 3",但遇到一些小问题.在我的视图中,当我编写如下代码时:

I´m starting to use "MVC 3" but I´m facing some little problems. In my Views, when I code something like this:

@if(Request.IsAuthenticated) {
    <text>Welcome <b>@Context.User.Identity.Name</b>!
    [ @Html.ActionLink("Log Off", "LogOff", "Account") ]</text>
}
else {
    @:[ @Html.ActionLink("Log On", "LogOn", "Account") ]
}

诸如@Request和@Html之类的对象指示错误:The name 'HTML' does not exist in the current context.

The objects like @Request and @Html is indicating an error: The name 'HTML' does not exist in the current context.

@ Context,@ ViewBag,@ Layout,@ Url和其他事件也会发生同样的情况.

The same occurs with @Context, @ViewBag, @Layout, @Url and others.

请参阅:

但是代码正确编译,没有错误.问题是我无法在视图中将Intellisense与这些对象一起使用.正常吗(我不这么认为).可能会发生什么?

But the code is correctly compiled with no errors. The problem is that I cannot use the Intellisense with theses objects in the Views. Is it normal? (I don´t think so). What could be happening?

我已经重新安装了MVC 3框架,但仍然会发生同样的情况.

I have reinstalled the MVC 3 framework but the same still occurs.

注意:这是从头开始的新项目,而不是MVC 2迁移. Razor引擎和ASPX都会发生这种情况.

Note: this is a new project from scratch, not a MVC 2 migration. This occurs both with Razor engine and ASPX.

这是Views文件夹中的Web.Config:

This is the Web.Config in the Views folder:

<?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.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>

谢谢!

推荐答案

我已经使用旧的,良好的,明智的Microsoft默认解决方案解决了这个问题:再次重新安装所有内容.

I have solved this issue with the old, good, wise Microsoft default solution: reinstall all the things again.

卸载并重新安装Visual Studio 2010和MVC 3 Framework.

Uninstall and Reinstall the Visual Studio 2010 and MVC 3 Framework.

这篇关于“名称"HTML"在当前上下文中不存在"在MVC 3视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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