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)
`<!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>`
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
InvalidOperationException: The partial view ‘_navbar’ was not found.
From this doc about “Partial view discovery”, you would find:
When a partial view is referenced by name without a file extension, the following locations are searched in the stated order:
MVC
- /Areas/<Area-Name>/Views/
- /Areas/<Area-Name>/Views/Shared
- /Views/Shared
- /Pages/Shared
To reference _navbar partial view, you can try these approaches:
-
As @ABDEL-RHMAN mentioned, you can try to move it to
/Views/Sharedfolder. -
Besides, if you do not want to change your folder structure, to make it work, you can try
@await Html.PartialAsync("../../shared/_navbar").
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0