Asp.net mvc 2 或在“/”应用程序中。---------------------------------------------------------------找不到资源。描述:HTTP404。您正在查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请

Asp.net mvc 2 或在“/”应用程序中。---------------------------------------------------------------找不到资源。描述:HTTP404。您正在查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请,asp.net-mvc-2,asp.net-mvc-routing,jquery-autocomplete,Asp.net Mvc 2,Asp.net Mvc Routing,Jquery Autocomplete,或在“/”应用程序中。---------------------------------------------------------------找不到资源。描述:HTTP404。您正在查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请检查以下URL并确保其拼写正确。请求的URL:/index/search您在ajax调用中是否正确设置了URL?我的意思是指你的行动……我不确定这是我第一个使用MVC2的项目,也不太熟悉.NET。我想我没有正确配置路由表,我在上面的代码中间包含


或在“/”应用程序中。---------------------------------------------------------------找不到资源。描述:HTTP404。您正在查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请检查以下URL并确保其拼写正确。请求的URL:/index/search您在ajax调用中是否正确设置了URL?我的意思是指你的行动……我不确定这是我第一个使用MVC2的项目,也不太熟悉.NET。我想我没有正确配置路由表,我在上面的代码中间包含了这些表。我对全局页面中的路线表有些困惑。好吧,当我颠倒了第一条和第三条地图路线的顺序并运行应用程序时。一旦我输入一个名称并单击搜索,它将返回到搜索页面,没有任何信息,并要求我输入另一个名称进行搜索。。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using DOC_Kools.Models;

namespace DOC_Kools.Controllers
{
    public class HomeController : Controller
    {
        private KOOLSEntities _dataModel = new KOOLSEntities();

        //
        // GET: /Home/

        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            return View();

        }

        //
        // GET: /Home/

        public ActionResult getAjaxResult(string q)
        {
            string searchResult = string.Empty;

            var offenders = (from o in _dataModel.OffenderSet
                             where o.LastName.Contains(q)
                             orderby o.LastName
                             select o).Take(10);

            foreach (Offender o in offenders)
            {
                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 return detials
                // otherwise a list
                var offenders = from o in _dataModel.OffenderSet
                                where o.LastName.Contains(searchTerm)
                                orderby o.LastName
                                select o;

                if (offenders.Count() == 0)
                {
                    return View("not found");
                }

                if (offenders.Count() > 1)
                {
                    return View("List", offenders);
                }
                else
                {
                    return RedirectToAction("Details",
                        new { id = offenders.First().SPN });
                }
            }
        }


        //
        // GET: /Home/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Home/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Home/Create

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Home/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Home/Edit/5

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }

        }

        public ActionResult About()
        {
            return View();
        }

    }
}

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace DOC_Kools
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

            routes.MapRoute(
                "OffenderSearch",
                "Offenders/Search/{searchTerm}",
                new
                {
                    controller = "Home",
                    action = "Index",
                    searchTerm = ""
                }
                        );
            routes.MapRoute(
                "OffenderAjaxSearch",
                "Offenders/getAjaxResult/",
                new { controller = "Home", action = "getAjaxResult" }
                );


        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
        }
    }
}

    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<DOC_Kools.Models.Offender>" %>

<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
    <script src="../../Scripts/jquery.autocomplete.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>

 <script type="text/javascript">

     $(document).ready(function() {
         $("#searchTerm").autocomplete("/Offenders/getAjaxResult/");
     });

 </script>
    Home Page

</asp:Content>

<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%= Html.Encode(ViewData["Message"]) %></h2>


        <h2>Look for an offender</h2>

    <form action="/Offenders/Search" method="post" id="searchForm">
        <input type="text" name="searchTerm" id="searchTerm" value="" size="10" maxlength="30" />
        <input type="submit" value="Search" />

    </form>
    <br />



</asp:Content>