我是新来的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