Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WingtipToys.Models;>>>>>>>>>.This is my problem, the program shows that it does not exist in namespace.

using System.Web.ModelBinding;
using System.Web.Services.Description;




namespace RentingCarV2
{
    public partial class ProductList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public IQueryable<Product> GetProducts([QueryString("id")] int? categoryId)
        {
            var _db = new WingtipToys.Models.ProductContext();
            IQueryable<Product> query = _db.Products;
            if (categoryId.HasValue && categoryId > 0)
            {
                query = query.Where(p => p.CategoryID == categoryId);
            }
            return query;

        }
    }
}


What I have tried:

I searched for the namespace in my project but couldn't find it
Posted
Updated 29-Jul-22 18:48pm
v2
Comments
PIEBALDconsult 29-Jul-22 19:16pm    
Add a reference?
Afzaal Ahmad Zeeshan 29-Jul-22 19:17pm    
You need to add the reference to your project. Depending on your .NET version and the availability of the package, you might have to do that either via UI or via the CLI.

1 solution

The using statement creates a "shortcut" which allows you to use a class without specifying it's full name. YOu don't have to use them, but ...
C#
using System;
using System.IO;	
using System.Collections.Generic;

public class Program
	{
	static void Main(string[] args)
		{
		List<string> myList = new List<string>();
		...
		Console.ReadLine();
		}
	}

Is a lot more readable than:
C#
using System;
using System.IO;					
public class Program
	{
	static void Main(string[] args)
		{
		System.Collections.Generic.List<string> myList = new System.Collections.Generic.List<string>();
		...
		Console.ReadLine();
		}
	}
But in order to use a class from an assembly (and apart from the very basic value types everything is in an assembly of some form) it has to be added to the project by adding a reference to that assembly to the project: Manage references in a project - Visual Studio (Windows) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900