I'm new to ASP.NET MVC and I'm creating an app that will search a contact using using the autocomplete functionality along with jquery.
When I run the project it loads fine and when i click the submit button to search a lastname i receive an error.
Server Error in '/' Application.
The resource cannot be foundRequested URL:/Offender/Search
While attempting this project i followed along witht Northwind MVC Sample and that project also gave me errors as well.
Any help is appreciated! Thanks
The errors i receive are as follows:
Error 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
Error 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
Error 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();
}
}
}