0
votes

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();
        }
    }
}
2
It seems like your errors are compile errors, and not runtime errors, but you say the application starts fine. I would expect these types of errors when the framework dynamically compiles a view, but not in a controller which should be compiled before the web application starts. How many projects are in your solution, and how are they split?NerdFury
there's only one project in my solution.Bigced_21

2 Answers

1
votes

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

1
votes

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"/>
    ....