我是新來的ASP.NET MVC,我正在創建一個應用程序,使用自動完成功能和jQuery一起搜索聯繫人。ASP.NET MVC令人討厭的錯誤 - 無法找到類型或命名空間名稱
當我運行該項目時,它加載正常,當我點擊提交按鈕來搜索姓氏,我收到一個錯誤。
Server Error in '/' Application.
The resource cannot be foundRequested URL:/Offender/Search
在嘗試這個項目我也跟着一起witht羅斯文MVC樣品和項目也給了我的錯誤,以及。
任何幫助表示讚賞!是感謝
我接收的誤差如下:
錯誤1個
The type or namespace name 'KOOLSModel' could not be found (are you missing a using directive or an assembly reference?)
C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\DOC_KOOLS\DOC_KOOLS\Controllers\OffenderController.cs 6 7 DOC_KOOLS
錯誤2
The type or namespace name 'KOOLSEntities' could not be found (are you missing a using directive or an assembly reference?)
C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\DOC_KOOLS\DOC_KOOLS\Controllers\OffenderController.cs 15 32 DOC_KOOLS
錯誤3
The type or namespace name 'Offender' could not be found (are you missing a using directive or an assembly reference?)
C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\DOC_KOOLS\DOC_KOOLS\Controllers\OffenderController.cs 32 22 DOC_KOOLS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KOOLSModel;
namespace DOC_KOOLS.Controllers
{
public class OffenderController : Controller
{
//
// GET: /Offender/
//KOOLSEntities KOOLS = new KOOLSEntities();
KOOLSEntities db = new KOOLSEntities();
public ActionResult Index()
{
ViewData["Message"] = "Welcome to KOOL!";
return View();
}
public ActionResult getAjaxResult(string q)
{
string searchResult = string.Empty;
var offender = (from o in db.Offender
where o.Lastname.Contains(q)
orderby o.LastName
select o).Take(10);
foreach (Offender o in offender)
{
searchResult += string.Format("{0}|\r\n", o.LastName);
}
return Content(searchResult);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Search(string searchTerm)
{
if (searchTerm == string.Empty)
{
return View();
}
else
{
// if the search contains only one result retunr details
// otherwise a list
var offenders = from o in db.Offender
where o.LastName.Contains(searchTerm)
orderby o.LastName
select o;
if (offenders.Count() == 0)
{
return View("notfound");
}
if (offenders.Count > 1)
{
return View("List", offenders);
}
else
{
return RedirectToAction("Details", new { id = offenders.First().sPN });
}
}
}
public ActionResult About()
{
return View();
}
}
}
好像你的錯誤是編譯錯誤,而不是運行時錯誤,但你說應用程序啓動正常。我期望這些類型的錯誤,當框架動態編譯視圖,但不是在Web應用程序啓動之前應該編譯的控制器中。您的解決方案中有多少個項目,它們是如何分裂的? – NerdFury 2010-02-25 15:37:51
我的解決方案中只有一個項目。 – 2010-02-25 18:29:09