I created an aspx file and want to using a class from other project.
I tried using <%@ Import Namespace="DTO" %> in the aspx file, it showed 0 error, but when I run the project, the aspx file showed error: CS0246: The type or namespace name 'DTO' could not be found.
I also tried using the code below in Web.config file:
<pages>
<namespaces>
<add namespace="DTO"/>
</namespaces>
</pages>
It also showed 0 error, but when I run the project the aspx file show the same error.
I had added reference to other project, both my project using .Net Framework 4.5.2.
The visual studio always showed 0 error, but the aspx file always showed "CS0246: The type or namespace name 'DTO' could not be found." when I run.
Edit
This is the code I use in aspx file:
<%@ Page Title="" Language="C#" MasterPageFile="~/Default.Master" AutoEventWireup="true" CodeBehind="cart.aspx.cs" Inherits="Demo_MasterPage.cart" %>
<%@ Import Namespace="DTO" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<%
List<OrderItem> cart = Session["cart"] as List<OrderItem>;
%>
</asp:Content>
and this is the code of OrderItem class
namespace DTO
{
public class OrderItem
{
public int OrderId { get; set; }
public string ProductId { get; set; }
public int Quantity { get; set; }
public OrderItem()
{
}
public OrderItem(int orderId, string productId, int quantity)
{
OrderId = orderId;
ProductId = productId;
Quantity = quantity;
}
}
}
NameSpaceyou use inImport?