-4

The most confusing error I have ever seen in ASP. I have done method calls like this before, and have no issue in other spots of my code.

First of all the class:

namespace LocApp.Helpers.Classes.LocationHelper
{
    public class QueryHelper
    {
        private LocAppContext db = new LocAppContext();

        public static IEnumerable<Service> getAllService()
        {
            using (var db = new LocAppContext())
            {
                var service = db.Locations.Include(s => s.LocationAssignment);

                var serv = (from s in db.Services
                            where s.active == true
                            select s).ToList();
                return serv;
            }
        }
    }
}

Pretty easy to understand whats going on. So lets call the method:

IEnumerable<LocApp.Models.Service> Service = new LocApp.Helpers.Classes.LocationHelper.QueryHelper.getAllService(Model.id);

getAllServices(Model.id) is throwing the error "is a method but treated like a type" , um no its not be treated like a type....

whats going on?

TheWebs
  • 12,470
  • 30
  • 107
  • 211
  • 2
    `getAllService()` does not have any input parameters, but you are trying to pass `id` to this method – Sergey Berezovskiy Apr 19 '13 at 15:53
  • 2
    For future reference: you should post the exact errors that you're getting, and you'll probably want to distinguish between *compilation* errors and *runtime* errors for people. (Here it's not compiling). You can tell the difference based on whether or not you can run it. (remember "Build and Run" is two separate steps) – Chris Pfohl Apr 19 '13 at 15:59
  • possible duplicate of [File Upload ASP.NET MVC 3.0](http://stackoverflow.com/questions/5193842/file-upload-asp-net-mvc-3-0) – TheWebs Feb 19 '15 at 07:04

3 Answers3

5

Well it's exactly as the error message says. getAllService() is a method:

public static IEnumerable<Service> getAllService()

But you're trying to use it as if it were a type with a constructor:

Service = new LocApp.Helpers.Classes.LocationHelper.QueryHelper.getAllService(...)

The new part is the mistake here. You don't want to call a constructor, you just want to call a method. It's a static method, so you don't need an instance - you can just use:

Service = LocApp.Helpers.Classes.LocationHelper.QueryHelper.getAllService(...)

Note that if you have appropriate using directives, follow .NET naming conventions and take care about singular/plural names, your code will be easier to follow:

var services = QueryHelper.GetAllServices(...);
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
2

Do you not simply mean:

IEnumerable<LocApp.Models.Service> Service = LocApp.Helpers.Classes.LocationHelper.QueryHelper.getAllService();

Get rid of the new bit, essentially, and that method doesn't take any parameters either - I'd assume you'd run into that problem after you removed the new bit.

Arran
  • 24,648
  • 6
  • 68
  • 78
1

Your getAllService method doesn't take any arguments, so you should call it without. Also it is a static method so don't use the new keyword:

IEnumerable<LocApp.Models.Service> Service = LocApp.Helpers.Classes.LocationHelper.QueryHelper.getAllService();
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928