How to Load Views from Database in MVC

By June 16, 2014 .NET, ASP.NET, C#, MVC, Web No Comments

We may need to store views in database tables and tell MVC engine to look for views from database instead on file system. This way, we can also define the hierarchy of pages. I’m going to use my previous implementation of loading views from assembly and with a few modifications, we will make that work for our database. First off, we will create a table named Page with the following schema.


We will now modify methods IsExistByVirtualPath and GetByVirtualPath which will look for views in table and return it’s content.


Views will now load from the database. Download the sample project from here.

Happy Coding!

And we know you want to learn more! So, register now for FalafelCon 2014 and perfect your skills, expand your horizons, and get inspired.

The following two tabs change content below.

Saad Khan

Software Engineer at Falafel Software
Saad is an ASP.NET developer with 4 years of experience, and has also made a number of contributions to the Sitefinity marketplace and community. He loves to explore new code, and create innovative tools and procedures while exploring new approaches in his work with Sitefinity and MVC. As an experienced .NET developer, he frequents both Telerik and Microsoft technologies. In his spare time, Saad is an avid gamer and movie fanatic, and also experiments with new and interesting tools on the Microsoft platform.​​

Latest posts by Saad Khan (see all)