Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Location for _ViewImport.cshtml & _ViewStart.cshtml not using ViewLocationExpander? #2990

Closed
jhermsen opened this issue Aug 18, 2015 · 9 comments
Milestone

Comments

@jhermsen
Copy link

I am not sure if it is by design, but the locations for _ViewImport.cshtml and _ViewStart.cshtml the used IViewLocationExpander is not processed.
As a workaround I extended my FileProvider to do it for those files.

@jhermsen
Copy link
Author

Nevermind, made a mistake.

@jhermsen
Copy link
Author

They are passed using path from loaded View and not a processed path from the IViewLocationExpander like I expected.
Also the path for _ViewImport.cshtml and _ViewStart.cshtml are passed to FileProvider.GetFileInfo with backslashed instead of forward slashes.
Why was this method chosen for these files?

The problem is I use an IViewLocationExpander class to add a certain prefix, but for _ViewImport.cshtml and _ViewStart.cshtml I need a different prefix. For now I use my FileProvider to replace the prefix.

@jhermsen jhermsen reopened this Aug 18, 2015
@danroth27
Copy link
Member

@pranavkm

Both _ViewImport.cshtml and _ViewStart.cshtml are handled in a hierarchical fashion based on the path of the view that is found, which is intended.

Can you tell us more about what you are trying to accomplish? Why do you nee to add a path prefix?

@jhermsen
Copy link
Author

I use and IViewLocationExpander to add prefixes based on the current controller to determine the assembly.
And in a custom IFileProvider I use those prefixes to determine the assembly containing the embedded view.
And for shared views like the _layout.cshtml and _viewimports.cshtml I have a specific assembly to fallback on.

@danroth27
Copy link
Member

Can you tell us why you are resolving views in this way? Is this intended to enable some sort of component model?

@jhermsen
Copy link
Author

Yes, I want to make it a modular solution where the module can contain controllers and embedded views.

@danroth27
Copy link
Member

Can you show us an example of how you are setting this up? What do these components look like? Why do you need the fallback behavior for these specific files?

@jhermsen
Copy link
Author

jhermsen commented Sep 8, 2015

IViewLocationExpander adds a location with prefix like "#Module#" based on the controller assembly used and also a locationwith prefix like "#Shared#" as a fallback incase specific view isn't in the module assembly (Also for _layout, _ViewImports and _ViewStart).
So basicly for a home controller's index view the locations will be something like [/Views/Home/Index.cshtml, #Module#/Views/Home/Index.cshtml, #Shared#/Views/Home/Index.cshtml].

And in the IFileProvider I get the view based on the location, if a prefix is present check in the module assembly resources.

@rynowak
Copy link
Member

rynowak commented Jul 14, 2017

If you really want this today you can subclass and replace FileProviderRazorProject which is what we use to find _ViewImports. However, since this won't really play with tooling, we don't recommend coming up with alternative organizations of these files.

Suggest closing this /cc @Eilon

@Eilon Eilon closed this as completed Jul 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants