views:

266

answers:

2

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 found

Requested 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();
        }
    }
}
A: 

It looks like you didn't add a reference to the assembly containing the entity model.

SLaks
I just added System.Data "
Bigced_21
What reference would i need to add?
Bigced_21
A: 

Have you added the reference to your web.config? If any of your views are strongly typed then you will require to add a section in the 'pages' section of your web.config

<pages>
    ...
    <add namespace="KOOLSModel"/>
    <add namespace="System.Web.Mvc"/>
    ....
David Liddle
No i haven't, does it matter if i add it to the web.config at the view level or the root level
Bigced_21
I get a Configuration Error when i run it. the <add namespace="System.Web.Mvc"/> already existed in the web.config
Bigced_21
Put it in the root web.config of your site. Not the config that's in the view folder.
David Liddle
Ok, after inserting the namespace and when i run the page i get a Parser Error stating Could not load type "DOC_KOOLS.MvcApplication' Source Error: Line 1: <%@ Application Codebehind="Global.asax.cs" Inherits="DOC_KOOLS.MvcApplication" Language="C#" %>
Bigced_21