ASP Net Core 3中的错误未找到部分视图

问题描述

InvalidOperationException: The partial view '_navbar' was not found. 
The following locations were searched:
/Views/Home/_navbar.cshtml
/Views/Shared/_navbar.cshtml
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.RenderPartialCoreAsync(string partialViewName,object model,ViewDataDictionary viewData,TextWriter writer)

enter image description here

`<!DOCTYPE html>
<html>
<head>
    <Meta charset="utf-8" />
    <title>Index</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5paxtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<body>
    @await Html.PartialAsync("_navbar")

    <p>@ViewBag.Greeting @ViewBag.UserName,Necesiniz?</p>
    <p>Umid edirem memnunsuzx</p>
</body>
</html>`

解决方法

InvalidOperationException:找不到部分视图“ _navbar”。

this doc about "Partial view discovery"中,您会发现:

当按名称引用不带文件扩展名的部分视图时,将按所述顺序搜索以下位置:

MVC

  1. / Areas / / Views /
  2. /区域/ /视图/共享
  3. /视图/共享
  4. /页面/共享

要引用--------------------------------------------------------------------------- XGBoostError Traceback (most recent call last) <ipython-input-11-60e28ccb95f6> in <module> 1 ## Hyperparameter optimization using RandomizedSearchCV 2 from sklearn.model_selection import RandomizedSearchCV,GridSearchCV ----> 3 import xgboost ~/opt/anaconda3/lib/python3.8/site-packages/xgboost/__init__.py in <module> 7 import os 8 ----> 9 from .core import DMatrix,DeviceQuantileDMatrix,Booster 10 from .training import train,cv 11 from . import rabit # noqa ~/opt/anaconda3/lib/python3.8/site-packages/xgboost/core.py in <module> 171 172 # load the XGBoost library globally --> 173 _LIB = _load_lib() 174 175 ~/opt/anaconda3/lib/python3.8/site-packages/xgboost/core.py in _load_lib() 154 if not lib_success: 155 libname = os.path.basename(lib_paths[0]) --> 156 raise XGBoostError( 157 'XGBoost Library ({}) could not be loaded.\n'.format(libname) + 158 'Likely causes:\n' + XGBoostError: XGBoost Library (libxgboost.dylib) could not be loaded. Likely causes: * OpenMP runtime is not installed (vcomp140.dll or libgomp-1.dll for Windows,libomp.dylib for Mac OSX,libgomp.so for Linux and other UNIX-like OSes). Mac OSX users: Run `brew install libomp` to install OpenMP runtime. * You are running 32-bit Python on a 64-bit OS Error message(s): ['dlopen(/Users/danishali/opt/anaconda3/lib/python3.8/site-packages/xgboost/lib/libxgboost.dylib,6): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib\n Referenced from: /Users/danishali/opt/anaconda3/lib/python3.8/site-packages/xgboost/lib/libxgboost.dylib\n Reason: image not found'] 部分视图,可以尝试以下方法:

  1. 如@ ABDEL-RHMAN所述,您可以尝试将其移动到_navbar文件夹中。

  2. 此外,如果您不想更改文件夹结构以使其正常运行,则可以尝试/Views/Shared