我正在做一个C#教程,但是这个错误无法继续,我已经在App_Code文件夹下设置了Product类,不知何故没有加载或导入它。知道为什么吗?
>开始ASP.NET 4'应用程序中的服务器错误。 编译错误描述:编译服务此请求所需的资源时发生错误。请查看以下特定错误详细信息并适当修改源代码。
编译器错误消息:CS0246:找不到类型或命名空间名称“Product”(您是否缺少using指令或程序集引用?)**
源文件:c:\ Documents and Settings \ Desktop \ Books \ Beginning ASP.NET 4 \ Chapter03 \ Website \ Default.aspx Line:8
来源错误:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
private void Page_Load(object sender, EventArgs e)
{
Product saleProduct = new Product("Kitchen Garbage", 49.99M, "garbage.jpg");
Response.Write(saleProduct.GetHtml());
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Product Test</title>
</head>
<body></body>
</html>
答案 0 :(得分:0)
尝试使用
Product saleProduct = new Product("Kitchen Garbage", "49.99M", "garbage.jpg");
将双引号设为49.99M
答案 1 :(得分:0)
试试这个 App_Code文件/ Product.cs
public class Product
{
public Product()
{
//
// TODO: Add constructor logic here
//
}
public string ProductName { get; set; }
public string Property2 { get; set; }
public string Image { get; set; }
public Product(string _ProductName, string _Property2, string _Image)
{
this.ProductName = _ProductName;
this.Property2 = _Property2;
this.Image = _Image;
}
public string GetHtml
{
get
{
StringBuilder sb = new StringBuilder();
sb.Append("<table>");
sb.Append(string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", this.ProductName, this.Property2, this.Image));
sb.Append("<table>");
return sb.ToString();
}
}
}
这是Default.aspx.cs文件中的代码。
protected void Page_Load(object sender, EventArgs e)
{
Product saleProduct = new Product("Kitchen Garbage", "49.99M", "garbage.jpg");
Response.Write(saleProduct.GetHtml);
}