0

I want to render partial view in my asp.net core application.

Earlier i was using @Html.Partial() function but VS suggested me to change it to normal <partial> and from that moment i am using it like that since i rendered only few partial views so i stored them in shared folder but now i started using it more often and problem i am having is i want to sort them in folders.

I looked at answers but all are using @Html.Partial() like this one but no answer with normal <patial> tag.

I tired doing it like this:

<partial name='~/Folder/View' model='new Model()' but it is not working just as any combination with/without ~ / and other signs.

Aleksa Ristic
  • 2,394
  • 3
  • 23
  • 54
  • Is there any error? – habib Sep 30 '19 at 04:04
  • `InvalidOperationException: The partial view '~/Reservation/New' was not found. The following locations were searched: ~/Reservation/New` When i put same view in shared folder and call it only by name it works – Aleksa Ristic Sep 30 '19 at 04:05
  • It seems your path for Partial View is not valid. Please try to specify the complete path from your app root. Like this ~/Areas/Admin/Views/StoreMenu/CreateOrEdit.cshtml – habib Sep 30 '19 at 04:15
  • I was already trying it but not exactly.... Big hint is to add `.cshtml` at the end.... If you use it from shared folder you do not need it but like this you need it. – Aleksa Ristic Sep 30 '19 at 04:27
  • Please share your partial view complete path. – habib Sep 30 '19 at 04:30
  • It's now `~/Views/Reservation/New.cshtml` and all time i was trying `~/Views/Reservatoin/New` – Aleksa Ristic Sep 30 '19 at 05:58

1 Answers1

1

The name attribute is required. It indicates the name or the path of the partial view to be rendered. When a partial view name is provided, the view discovery process is initiated. That process is bypassed when an explicit path is provided. For all acceptable name values, see Partial view discovery.

Reference :

https://learn.microsoft.com/en-us/aspnet/core/mvc/views/partial?view=aspnetcore-2.2

Xueli Chen
  • 11,987
  • 3
  • 25
  • 36