Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6750885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:51:39+00:00 2026-05-26T12:51:39+00:00

I have online form builder appplication in ASP.NET MVC3 with Razor views. It is

  • 0

I have online form builder appplication in ASP.NET MVC3 with Razor views.
It is similar to this – https://examples.wufoo.com/forms/workshop-registration/

I need users to be able to customize the page design.
Not only to upload a custom css, but also to customize the HTML page template.
Let’s say users should have complete control on Layout’s HTML for their custom webform page. User should be able to edit any HTML on the page, beside the form that is included into the layout.

I’m not sure how to do that with Razor and ASP.NET MVC 3.
Is it possible to:

  1. load layout somewhere from database as string or whatever
  2. replace some custom tags like “FORM1_INCLUDE” to
    @Html.Partial(“some_non_customizable_layout_for_form1”)
  3. use the result as a valid Layout file for the user’s form page

Maybe 1-3 is not the best way to do what I need.
What can you suggest for such user defined page layout approach in ASP.NET MVC 3 with Razor views?

UPDATE 1
Using VirtualPathProvider I was able to load View from database, but it just returns text like:

@inherits System.Web.Mvc.WebViewPage
<body>
@Html.EditorFor(z => z.Customer)
</body>

and doesn’t process any Razor syntax at all.
What could be the problem with it?

SOLVED:

Needed to place this line as the first one in Application_Start() method:

HostingEnvironment.RegisterVirtualPathProvider(new MyVirtualPathProvider());

UPDATE 2
Custom View Provider is registered in Global.asax.cs as:

protected void Application_Start()
        {
            HostingEnvironment.RegisterVirtualPathProvider(new MyVirtualPathProvider());

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }

MyVirtualPathProvider code is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Hosting;
using System.IO;
using System.Text;

namespace new_frontend
{
    public class MyVirtualPathProvider : VirtualPathProvider
    {
        public override bool FileExists(string virtualPath)
        {
            var td = FindTemplate(virtualPath);
            if (td == null)
            {
                return true;
                //return base.FileExists(virtualPath);
            }
            else
            {
                return true;
            }
        }

        public override VirtualFile GetFile(string virtualPath)
        {
            var td = FindTemplate(virtualPath);
            if (td == null)
            {
                return new MyVirtualFile(virtualPath, "");
                //return base.GetFile(virtualPath);
            }
            else
            {
                return new MyVirtualFile(virtualPath, td.ContentStep1);
            }
        }

        private Facade.Dto.TemplateData FindTemplate(string virtualPath)
        {
            string prefix = "Template#";

            int id = 0;
            Facade.Dto.TemplateData td = null;

            string fileName = System.IO.Path.GetFileNameWithoutExtension(virtualPath);
            if (fileName.StartsWith(prefix))
                Int32.TryParse(fileName.Substring(prefix.Length), out id);

            if (id > 0)
                td = Facade.FrontEndServices.GetTemplate(id);

            return td;
        }
    }

    public class MyVirtualFile : VirtualFile
    {
        private byte[] data;

        public MyVirtualFile(string virtualPath, string body)
            : base(virtualPath)
        {                      // 'System.Web.WebPages.ApplicationStartPage
            string _body = /*body +*/ @"

@inherits System.Web.Mvc.WebViewPage
@using (Ajax.BeginForm(""Submit"", new AjaxOptions { UpdateTargetId = ""main"" }))
{
}
<!-- <PERSONAL_INFO> -->
<div id=""personal_info"" class=""op2-block"">

</div>
<!-- <PERSONAL_INFO> -->";

            this.data = Encoding.UTF8.GetBytes(_body);
        }

        public override System.IO.Stream Open()
        {
            return new MemoryStream(data);
        }
    }
}

And now for the Razor view code defined as a string above I get this exception:

“Compiler Error Message: CS1061: ‘System.Web.Mvc.AjaxHelper’ does not contain a definition for ‘BeginForm’ and no extension method ‘BeginForm’ accepting a first argument of type ‘System.Web.Mvc.AjaxHelper’ could be found (are you missing a using directive or an assembly reference?)”

And when I changed Razor View code to:

string _body = /*body +*/ @"

@using System.Web.WebPages;
@using System.Web.Mvc;
@using System.Web.Mvc.Ajax;
@using System.Web.Mvc.Html;
@using System.Web.Routing;

@inherits System.Web.Mvc.WebViewPage<dynamic>

@using (Ajax.BeginForm(""Submit"", new AjaxOptions { UpdateTargetId = ""main"" }))
{
}
<!-- <PERSONAL_INFO> -->
<div id=""ppg_op2_personal_info"" class=""op2-block"">

</div>
<!-- <PERSONAL_INFO> -->";

I got a different error:

Type ‘ASP._Page__appstart_cshtml’ does not inherit from ‘System.Web.WebPages.ApplicationStartPage’

When I change

@inherits System.Web.Mvc.WebViewPage

to

@inherits System.Web.WebPages.ApplicationStartPage

to fix the error above, I get a new one:

“Compiler Error Message: CS0103: The name ‘Ajax’ does not exist in the current context”

UPDATE3:
I tried to use base.XXX:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Hosting;
using System.IO;
using System.Text;

namespace new_frontend
{
    public class MyVirtualPathProvider : VirtualPathProvider
    {
        public override bool FileExists(string virtualPath)
        {
            var td = FindTemplate(virtualPath);
            if (td == null)
            {
                //return true;
                return base.FileExists(virtualPath);
            }
            else
            {
                return true;
            }
        }

        public override VirtualFile GetFile(string virtualPath)
        {
            var td = FindTemplate(virtualPath);
            if (td == null)
            {
                //return new MyVirtualFile(virtualPath, "");
                return base.GetFile(virtualPath);
            }
            else
            {
                return new MyVirtualFile(virtualPath, td.ContentStep1);
            }
        }

        private Facade.Dto.TemplateData FindTemplate(string virtualPath)
        {
            string prefix = "Template#";

            int id = 0;
            Facade.Dto.TemplateData td = null;

            string fileName = System.IO.Path.GetFileNameWithoutExtension(virtualPath);
            if (fileName.StartsWith(prefix))
                Int32.TryParse(fileName.Substring(prefix.Length), out id);

            if (id > 0)
                td = Facade.FrontEndServices.GetTemplate(id);

            return td;
        }
    }

    public class MyVirtualFile : VirtualFile
    {
        private byte[] data;

        public MyVirtualFile(string virtualPath, string body)
            : base(virtualPath)
        {                      // 'System.Web.WebPages.ApplicationStartPage
            string _body = /*body +*/ @"

@inherits System.Web.Mvc.WebViewPage<PPG.Facade.Dto.NewOrderPageData>
@using (Ajax.BeginForm(""Submit"", new AjaxOptions { UpdateTargetId = ""main"" }))
{
}
<!-- <PERSONAL_INFO> -->
<div id=""personal_info"" class=""op2-block"">

</div>
<!-- <PERSONAL_INFO> -->";

            this.data = Encoding.UTF8.GetBytes(_body);
        }

        public override System.IO.Stream Open()
        {
            return new MemoryStream(data);
        }
    }
}

In this case I get a view that is not parsed at all, this is what I get in the web browser:

@using System.Web.WebPages;    
@using System.Web.Mvc;    
@using System.Web.Mvc.Ajax;    
@using System.Web.Mvc.Html;    
@using System.Web.Routing;    
@inherits System.Web.Mvc.WebViewPage<PPG.Facade.Dto.NewOrderPageData>
@using (Ajax.BeginForm("Submit", new AjaxOptions { UpdateTargetId = "main" }))
{
}
<!-- <PERSONAL_INFO> -->
<div id="ppg_op2_personal_info" class="op2-block">
</div>
<!-- <PERSONAL_INFO> -->
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:51:40+00:00Added an answer on May 26, 2026 at 12:51 pm

    You should create a virtual path provider which fetches your custom views from a database.

    There are several questions here about them. Just search for VirtualPathProvider

    Updates (from my comments to the question discussion)

    • The VirtualPathProvider must be registered in Application_Start using HostingEnvironment.RegisterVirtualPathProvider(new MyVirtualPathProvider());

    • The base class MUST be called for all files that you can’t currently serve. This is required since there can only be one VirtualPathProvider. (You’ll see lots of strange errors otherwise)

    • @model directive doesn’t work in files that you serve. You must use @inherits System.Web.Mvc.WebViewPage<YourNameSpace.YourModelName> instead.

    • IIRC you also need to override GetCacheDependency and return null for your own resources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created online exam application (web based) in asp.net c#. In my application
I have an online form which collects member(s) information and stores it into a
I have an online form which collects consumer data and stores in a dedicated
I have an online gateway which requires an HTML form to be submitted with
I have created a form online and when the user clicks submit I want
I'm working on an online form builder tool (specifically for insurance agents). One of
I have an online form. for example it asks for first name and last
I've an online form: http://yoursdproperty.com/index.php?option=com_chronocontact&Itemid=56 I would like to have some faint gray text
I have a web form that users complete online. When they press submit it
I am working on an online form. Before a user fills in this form,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.