'/' 中的服务器错误应用。 - 找不到资源

发布于 2024-08-24 22:39:01 字数 6286 浏览 5 评论 0原文

我是 ASP.NET MVC 2 的新手。 我不明白为什么会收到此错误。是否缺少一些我没有正确引用的内容。

我正在尝试创建一个简单的 jquery 自动完成在线搜索文本框,并查看我选择的人员的详细信息,

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>

我需要做什么才能使文本框搜索显示在索引页上? 为了使自动完成功能正常运行,我还需要做什么。我有 autocomplete.js & jquery.js 添加到 index.aspx 视图

任何帮助将不胜感激,以便我可以正常工作。

谢谢!

I am new to ASP.NET MVC 2.
I do not understand why I am receiving this error. Is there something missing that i'm not referencing correctly.

I'm trying to create a simple jquery autocomplete online search textbox and view the details of the person that i select

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>

what do i have to do in order for the textbox search to display on the index page?
What else do i have to do for the autocomplete to function correctly. i have the autocomplete.js & jquery.js added to the index.aspx view

Any help will be appreciated so that i can get this working.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁虫ゝ 2024-08-31 22:39:01

也许这是 global.asax 中路线的顺序?
尝试颠倒顺序。我认为它试图从头到尾找到正确的路线,在你的情况下,它总是停在第一条路线上,即:“{controller}/{action}/{id}”...

maybe it's the order of the routes in the global.asax ?
try and reverse the order. i think that it tries to find the right routes from first to last and in your case it always stopes at the first route which is: "{controller}/{action}/{id}" ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文