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 9155229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:33:22+00:00 2026-06-17T12:33:22+00:00

I’ve read a post about changing base view type on MVC from the link

  • 0

I’ve read a post about changing base view type on MVC from the link below:

http://haacked.com/archive/2011/02/21/changing-base-type-of-a-razor-view.aspx

I followed the instructions but my page still inherits from System.Web.Mvc.WebViewPage. I can’t reach any property defined in my custom view base and I get an error on runtime. When I use @inherits keyword, it fixes.

Web.config

<pages pageBaseType="[MyNamespace].WebViewPageBase">
  <namespaces>
    <add namespace="System.Web.Helpers" />
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Optimization" />
    <add namespace="System.Web.Routing" />
    <add namespace="System.Web.WebPages" />
  </namespaces>
</pages>

WebViewPageBase

public class WebViewPageBase : WebViewPage
{
    public SomeType MyProperty { get; set; }

    public override void InitHelpers()
    {
        base.InitHelpers();
        MyProperty = { foo };
    }

    public override void Execute()
    {

    }
}


public class WebViewPageBase<T> : WebViewPage<T>
{
    public SomeType MyProperty { get; set; }

    public override void InitHelpers()
    {
        base.InitHelpers();
        MyProperty = { foo };
    }

    public override void Execute()
    {

    }
}

Partial View

@model TopMenuModel

<div class="topMenu">
@MyProperty
</div>

But in the post I’ve read there is no instruction about @inherits keyword. Is there any thing that I miss or any way to make this work without @inherits keyword in all pages?

SOLVED:

web.config file in root directory is not the right one. I changed base type in the web.config file under View directory and it fixed.

  • 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-06-17T12:33:23+00:00Added an answer on June 17, 2026 at 12:33 pm

    Why did you show two versions of WebViewPageBase: generic and non-generic?

    You only need the generic version:

    public class MyWebView<T> : WebViewPage<T>
    {
        public SomeType MyProperty { get; set; }
    
        public override void InitHelpers()
        {
            base.InitHelpers();
            MyProperty = new SomeType();
        }
    
        public override void Execute()
        {
        }
    }
    

    and then:

    <pages pageBaseType="MvcApplication1.WebViews.MyWebView">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
    

    Now inside your views you will be able to use the property:

    @model TopMenuModel
    
    <div class="topMenu">
        @MyProperty
    </div>
    

    UPDATE:

    Step by step setup:

    1. Create a new ASP.NET MVC 3 application using the Internet Template
    2. Add a custom base view:

      namespace MvcApplication1
      {
          public class MyWebView<T> : WebViewPage<T>
          {
              public string MyProperty { get; set; }
      
              public override void InitHelpers()
              {
                  base.InitHelpers();
                  MyProperty = "Hello World";
              }
      
              public override void Execute()
              {
              }
          }
      }
      
    3. Set the pageBaseType attribute in ~/Views/web.config (not to be confused with ~/web.config):

      <pages pageBaseType="MvcApplication1.MyWebView">
        <namespaces>
          <add namespace="System.Web.Mvc" />
          <add namespace="System.Web.Mvc.Ajax" />
          <add namespace="System.Web.Mvc.Html" />
          <add namespace="System.Web.Routing" />
        </namespaces>
      </pages>
      
    4. Inside ~/Views/Home/Index.cshtml use the property:

      <div>
          @MyProperty
      </div>
      
    5. Hit Ctrl+F5 to run the application and if everything goes well you will be greeted with a Hello World.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.