加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 在ASP.NET网页中枚举字典

发布时间:2020-12-16 00:13:24 所属栏目:百科 来源:网络整理
导读:我有一个ASP.NET(C#)网页,我想在代码渲染块中枚举一个字典: % foreach (Dictionarystring,string record in parsedData) { % div...Some HTML Code.../div% } % 但我得到一个错误: Compiler Error Message: CS0246: The type or namespace name ‘Dictiona
我有一个ASP.NET(C#)网页,我想在代码渲染块中枚举一个字典:

<% foreach (Dictionary<string,string> record in parsedData) { %>
     <div>...Some HTML Code...</div>
<% } %>

但我得到一个错误:

Compiler Error Message: CS0246: The
type or namespace name ‘Dictionary’
could not be found (are you missing a
using directive or an assembly
reference?)

如何将System.Collections.Generic导入页面本身?这是我的页面指令:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyCSharpClass.aspx.cs" Inherits="_MyCSharpClass" %>

解决方法

你可以通过多种方式实现这一目标.

在web.config中,您可以将System.Collections.Generic添加到namespaces元素.

您也可以直接将其引用为System.Collections.Generic.Dictionary< string,string>

你也应该能够直接在页面上做这件事(虽然我必须承认我没有用这种方式测试过):

<%@ Import Namespace="System.Collections.Generic" %>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读