error in asp net core 3 the partial view was not found

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>`

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

  1. /Areas/<Area-Name>/Views/
  2. /Areas/<Area-Name>/Views/Shared
  3. /Views/Shared
  4. /Pages/Shared

To reference _navbar partial view, you can try these approaches:

  1. As @ABDEL-RHMAN mentioned, you can try to move it to /Views/Shared folder.
  2. 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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x