mac*_*osh 3 c# asp.net import enumerate
我有一个ASP.NET(C#)网页,我想在代码渲染块中枚举一个字典:
<% foreach (Dictionary<string, string> record in parsedData) { %>
<div>...Some HTML Code...</div>
<% } %>
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误:
编译器错误消息:CS0246:找不到类型或命名空间名称"Dictionary"(您是否缺少using指令或程序集引用?)
如何将System.Collections.Generic导入页面本身?这是我的页面指令:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyCSharpClass.aspx.cs" Inherits="_MyCSharpClass" %>
Run Code Online (Sandbox Code Playgroud)
你可以通过多种方式实现这一目标.
在web.config中,您可以添加System.Collections.Generic到namespaces元素.
您也可以直接引用它 System.Collections.Generic.Dictionary<string, string>
你也应该能够在页面上直接进行(虽然我必须承认我没有这样测试过):
<%@ Import Namespace="System.Collections.Generic" %>
Run Code Online (Sandbox Code Playgroud)