Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path in PartialView method ( to share them between applications)

Tags:

asp.net-mvc

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:

  1. If I create a common project in my solution as a sub domain, can I use a URL of it in other project's PartialView method?
  2. If I create common folder in my solution, I use a path something like "~/../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");

enter image description here

like image 781
Siamak Ferdos Avatar asked Jul 20 '16 06:07

Siamak Ferdos


1 Answers

  1. Can't be.
  2. Not a good idea.

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

like image 133
Mohammed Dawood Ansari Avatar answered Oct 11 '22 09:10

Mohammed Dawood Ansari