Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 视图';搜索';或者找不到其主节点,或者没有视图引擎支持搜索的位置_C#_Asp.net Mvc Views - Fatal编程技术网

C# 视图';搜索';或者找不到其主节点,或者没有视图引擎支持搜索的位置

C# 视图';搜索';或者找不到其主节点,或者没有视图引擎支持搜索的位置,c#,asp.net-mvc-views,C#,Asp.net Mvc Views,我正在尝试创建一个搜索参数,以从我在c#中创建的表中提取数据。运行应用程序会将我带到localhost:xxxx,它会显示整个表。我希望localhost:xxxx/movies/search/man用其中的字符串来提取我的数据 这是RouteConfig.cs public ActionResult Search(string name) { if (string.IsNullOrWhiteSpace(name)) {

我正在尝试创建一个搜索参数,以从我在c#中创建的表中提取数据。运行应用程序会将我带到localhost:xxxx,它会显示整个表。我希望localhost:xxxx/movies/search/man用其中的字符串来提取我的数据

这是RouteConfig.cs

    public ActionResult Search(string name)
    {

        if (string.IsNullOrWhiteSpace(name))
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }

        var movie = db.Movies.Where(x => x.Title.Contains(name)).FirstOrDefault();
        if (movie == null)
        {
            return HttpNotFound();
        }
        return View(movie);
    }
调用堆栈:

routes.MapRoute(
   name: "Search",
   url: "movies/search/{name}",
   defaults: new { controller = "Movies", action = "Search", name = UrlParameter.Optional }
);
[无效操作异常:未找到视图“搜索”或其主视图,或者没有视图引擎支持搜索的位置。搜索了以下位置:
~/Views/Movies/Search.aspx
~/Views/Movies/Search.ascx
~/Views/Shared/Search.aspx
~/Views/Shared/Search.ascx
~/Views/Movies/Search.cshtml
~/Views/Movies/Search.vbhtml
~/Views/Shared/Search.cshtml
~/Views/Shared/Search.vbhtml]
System.Web.Mvc.ViewResult.FindView(ControllerContext上下文)+382
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext上下文)+116
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext ControllerContext,ActionResult ActionResult)+13
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1过滤器、Int32过滤器索引、ResultExecutingContext预文本、ControllerContext ControllerContext、ActionResult ActionResult)+56
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1过滤器、Int32过滤器索引、ResultExecutingContext预文本、ControllerContext ControllerContext、ActionResult ActionResult)+420
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext ControllerContext,IList`1过滤器,ActionResult ActionResult)+52
System.Web.Mvc.Async.c__显示类2B.b__1c()+173
System.Web.Mvc.Async.c__显示Class21.b__1e(IAsyncResult asyncResult)+100
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)+10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+27
System.Web.Mvc.Controller.b_u1d(IAsyncResult asyncResult,ExecuteCorerate innerState)+13
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+49
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+36
System.Web.Mvc.Controller.b_u15(IAsyncResult asyncResult,Controller-Controller)+12
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+22
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+49
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+26
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)+10
System.Web.Mvc.MvcHandler.b_uu5(IAsyncResult asyncResult,ProcessRequestState innerState)+21
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+28
System.Web.Mvc.MvcHandler.System.Web.IHTTPassynchandler.EndProcessRequest(IAsyncResult结果)+9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+9748665
System.Web.HttpApplication.executesteppl(IExecutionStep步骤)+48
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+159

它看起来好像您还没有将其渲染到的视图

要添加视图(假定您使用的是ASP-MVC进入视图文件夹,请添加“Movies”文件夹(如果不存在),并在该文件夹下添加Search.cshtml文件,下面是一个示例:

这个答案是对您提供的堆栈跟踪的响应,这似乎与标题无关-读取堆栈跟踪这里的问题似乎不是Linq

希望这有助于公共操作结果搜索(字符串名称) {

  [InvalidOperationException: The view 'Search' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Movies/Search.aspx
~/Views/Movies/Search.ascx
~/Views/Shared/Search.aspx
~/Views/Shared/Search.ascx
~/Views/Movies/Search.cshtml
~/Views/Movies/Search.vbhtml
~/Views/Shared/Search.cshtml
~/Views/Shared/Search.vbhtml]
   System.Web.Mvc.ViewResult.FindView(ControllerContext context) +382
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +116
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +52
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +173
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9748665
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +159

感谢您的见解。这是视图的问题。我没有指向任何东西。出于我的目的,我只是指向我正在使用的索引。

断点…?!好的-您有搜索视图吗?请仔细阅读指南。到目前为止,没有任何迹象表明LINQ与您看到的错误有任何关联-请确保文章(和标题)有更好的样本和足够的信息来重现问题(包括你观点的文件位置)。很高兴我能帮上忙
        if (string.IsNullOrWhiteSpace(name))
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }

        var movies = db.Movies.Where(x => x.Title.Contains(name)).ToList();
        if (movies == null)
        {
            return HttpNotFound();
        }
        return View("index", movies);
    }