Asp.net mvc 对象上下文类MVC

Asp.net mvc 对象上下文类MVC,asp.net-mvc,Asp.net Mvc,我正试图从MVC应用程序中的控制器访问对象上下文类ForestDBEntities,ForestDBEntities位于models文件夹中。然而,它似乎没有找到它。我是否缺少模型的名称空间 代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace Forest.Controllers { publi

我正试图从MVC应用程序中的控制器访问对象上下文类
ForestDBEntities
ForestDBEntities
位于models文件夹中。然而,它似乎没有找到它。我是否缺少模型的名称空间

代码如下:

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

namespace Forest.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

       private forestDBEntities 
        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /Home/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Home/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Home/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Home/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Home/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Home/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Home/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }

}

很难说清楚,但很可能是的,您缺少了一个使用语句的
。很可能是
使用Forest.Models,或者您可以完全限定变量:
private-Forest.Models.ForestDbEntities
。顺便说一句-您的代码示例完全错误-小写
f
且没有分号。如果您想知道为什么VS不能使用
ctrl+。
,这也可能是您的问题的一部分。谢谢,就是这个问题