【发布时间】:2010-04-01 13:47:13
【问题描述】:
我有一个共享项目,其中存储了我的所有自定义 EditTemplates 和 DisplayTemplates。这是一个常规的 C# 类库项目,所有视图都标记为嵌入式资源。本项目的目标框架是“.Net Framework 4”。
在 /Views/ 文件夹中,我包含了这个 web.config 文件,因此在使用 .aspx 和 .ascx 文件时我得到了 MVC 2 intellisense:
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=2.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>
通常我对这个设置没有任何问题,但是当我编译我的视图时偶尔会出错:
错误 3 特征“匿名类型” 不能使用,因为它不是一部分 ISO-2 C# 语言的 规格
对于一个看起来像这样的模板:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="System.Web.Mvc.Html" %>
<%
string displayText = string.Empty;
if (Model != null)
{
if (DateTime.Parse(Model.ToString()) != DateTime.MinValue)
displayText = DateTime.Parse(Model.ToString()).ToShortDateString();
}
%>
<%= Html.TextBox("", displayText, new { @class = "date-box" })%>
大多数时候这个错误会消失。我已经学会了处理它,但现在它引起了一些问题。知道是什么原因导致“错误 3 功能‘匿名类型’无法使用,因为它不是 ISO-2 C# 语言规范的一部分”错误,以及如何解决这个问题?
【问题讨论】:
标签: c# visual-studio visual-studio-2010 asp.net-mvc-2