I want to share some Partial View between some applications. I tried different solutions which are suggested in internet, but none of them not work!
But I hope by using absolute or relation path in PartialView
method it works but I don't know is it possible or no.
So there are 2 questions here:
PartialView
method?"~/../Common/myView.cshtml"
. In this case Visual Studio not take error to me on editor by on runtime I got an error ("Cannot use a leading .. to exit above the top directory"). So is any solution to use a path of a common folder outside the root?I know that it'was better that I separate these question into 2 ones, but as there was no solution to share partial views I gather them here.
As you can see there is a Common folder in my solution which contains _MainMenu.cshtml
and also I have this file in Shared Folder in Website project too.
How should I write PartialView in Admin controller to path to each of them?
I want some code like these:
For Common folder:
return PartialView("~/../Common/_MainMenu.cshtml");
For shared folder:
return PartialView("http://localhost:16287/Module/Menu/_MainMenu");
Because that's not code which can be compiled to DLL and can be used by simply referencing it, it will be better you create Areas in you are application or replicate your views.
Edit : Razor Views CAN be compiled. But that doesn't change the fact that no View can be referenced by the Razor View Path resolver if it's located outside the Web Project. Virtual Paths could work. Thanks to @DaveAlperovich
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With