Question

I have number of projects that use different view engines (razor and webform). I want to share a partial view between them. I want to put my partial view in base project and just link partial views in my projects to it.

Looks like it isn't possible because partial view in razor and webform inherited from different base classes. Is it possible to hack this?

Was it helpful?

Solution

It was more simple that I though. WebForm can't take in Razor partial view. BUT Razor view engine takes in WebForm partial view. So it isn't issue at all.

What I did.

  1. Create some shared project.
  2. Add Partial.ascx file (and some js files) in sub folder of this shared project.
  3. Add reference to this project to my sub projects.
  4. Add as link partial view (and some js files) to sub projects.

So now we have partial view that is shared between number of projects.

PS: Be aware, my projects have only one view engine for improving performance. All other were removed: ViewEngines.Engines.Clear(); and added ViewEngines.Engines.Add(new RazorViewEngine()); Razor only. So I have to remove this code from my Global.asax file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top