Bill
Bill

Reputation: 19318

Beginner for App_code folder import

I am doing a C# tutorial, but got this error can't move on, I have set the Product class under the App_Code Folder, somehow is not loading or import it. any idea why?

Server Error in '/Beginning ASP.NET 4' Application. Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

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

Source File: c:\Documents and Settings\Desktop\Books\Beginning ASP.NET 4\Chapter03\Website\Default.aspx Line: 8

Source Error:

<%@ 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>

Upvotes: 0

Views: 752

Answers (2)

Paras
Paras

Reputation: 3067

Try this 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();

        }

    }


}

and this is the code from the Default.aspx.cs file.

 protected void Page_Load(object sender, EventArgs e)
{

    Product saleProduct = new Product("Kitchen Garbage", "49.99M", "garbage.jpg");
    Response.Write(saleProduct.GetHtml);
}

Upvotes: 0

MACMAN
MACMAN

Reputation: 1971

Try using

Product saleProduct = new Product("Kitchen Garbage", "49.99M", "garbage.jpg");

put double quotes for 49.99M

Upvotes: 0

Related Questions