Traditionally when using View renderings in Sitecore, if we didn’t want to use the built in Sitecore.Mvc.Presentation.RenderingModel model for our views we’d build a custom model and ensure Sitecore itself was aware of it by creating a Model item in /sitecore/layout/Models and fill in the Model field of the View rendering.
Without this Sitecore cannot resolve the model correctly:
So far, so old.
Being forced to add a model to Sitecore felt a bit limiting, and back in 2014 John West wrote a nice article demonstrating how to remove the need for specifying the model in Sitecore (since it is already present on the top of your view) https://community.sitecore.net/technical_blogs/b/sitecorejohn_blog/posts/determine-models-from-views-with-the-sitecore-asp-net-cms
Later on, Nat Mann ran with the idea and optimised the solution for performance: https://cardinalcore.co.uk/2015/03/24/getting-a-sitecore-model-from-the-cshtml-view/
Now we can use a custom model without the need to define the model in Sitecore. Sweet!
But what if you’re using Glass Mapper…
No problem, Glass has incorporated the GetModelFromhttps://github.com/mikeedwards83/Glass.Mapper/blob/master/Source/Glass.Mapper.Sc.Mvc/Pipelines/Response/GetModelFromView.csView code into the library as of release 220.127.116.11 adding the ability to determine the model required for a View Rendering from the Cshtml file itself.
This means you can happily use your Glass models with View Renderings and again, with no Sitecore Model admin.
All straight forward, but what if your views are precompiled (as Kamsar blogs about here) and don’t actually exist on disk?
Mike Edwards has happily provided the solution here.
Incorporating this code into your GlassMapperScCustom class will allows Glass to probe compiled view assemblies and locate the view.