Method must have a return type and Invalid Token '=' C# MVC4

First, I am fairly new to MVC. I am using VS2012, created a basic MVC Application. I am trying to make a Dropdown menu from an existing database table called "Schools". I did this by:

create a folder in solution Create a class

I, then, put the code below and I got 5 error messages:

  • Method must have a return type
  • Invalid token '=' in class, struct, or interface member declaration
  • Error 3 The type or namespace name 'InternshipProgramEntities_db' could not be found (are you missing a using directive or an assembly reference?)
  • Error 5 The name '_db' does not exist in the current context
  • Error 4 The name '_db' does not exist in the current context

Can someone please explain what's going on?

[EDIT: solved by fixing the space between _ and db] Thanks a lot!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using InternProject;
using InternProject.Models;

namespace InternProject.Classes
{
    public class Utilities
    {
        private readonly static InternshipProgramEntities_db = new InternshipProgramEntities();

        public IEnumerable<SelectListItem> SchoolDropdown()
        {

            var schools = _db.Schools.ToList();

            var items = new List<SelectListItem>();

            foreach (var s in schools)
            {
                items.Add(new SelectListItem()
                {
                    Text = s.SchoolName,
                    Value = string.Format("{0}", s.SchoolName)
                }
                );
            }

            return items;
     }
}//end of utilities class

Answers


private readonly static InternshipProgramEntities_db = new InternshipProgramEntities();

should be

private readonly static InternshipProgramEntities _db = new InternshipProgramEntities();

You forgot to add a space between the class type and instance name


Need Your Help

Multiple $match in PHP Mongo Aggregate

php mongodb

Im having issues using $match twice in a Mongo Aggregate query. As the query is entered into an array it appears to be overwriting the first $match with the second $match, and therefore not querying

Does using readfile to allow users to download images from my server without seeing the image's URL put strain on the server?

php ios mobile permissions

I'm building an iOS app that allows users to upload photos to an upload folder on my server and send them to their friends. Right now I have the permissions on the uploads folder set to 773 (write,