List Dictionary in ASP.NET Web Page

I have an ASP.NET (C #) webpage in which I want to list a dictionary in a code rendering block:

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

But I get an error message:

Compiler Error Message: CS0246: The type or name of the Dictionary namespace could not be found (you don’t see using the directive or assembly link?)

How to import System.Collections.Generic into the page itself? Here is my page directive:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyCSharpClass.aspx.cs" Inherits="_MyCSharpClass" %>
+3
source share
3 answers

You can do this in several ways.

In your web.config you can add System.Collections.Genericnamespaces to the element.

You can also refer to it as System.Collections.Generic.Dictionary<string, string>

( , ):

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

import .aspx.

.,

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

Add this at the top of the * .aspx page

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

+2
source

Source: https://habr.com/ru/post/1741995/


All Articles