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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:51:01+00:00 2026-05-27T13:51:01+00:00

I’m learning ASP.NET MVC3 and doing an application with CMS capabilities – but have

  • 0

I’m learning ASP.NET MVC3 and doing an application with CMS capabilities – but have run into some problems.

The basic idea is that all pages are connected to a pagetype, which in turn have a set of properties connected to it.

Works great if I’m only using string values, but I want to be able to type all properties (String, LongString, XhtmlString, Number and TrueFalse).

This is my models that I have come up with.

public class Page
{
    public int PageId { get; set; }
    public int PageTypeId { get; set; }
    public string Name { get; set; }

    public PageType PageType { get; set; }

    public List<PropertyValues> Properties { get; set; }
}

public class PageType
{
    public int PageTypeId { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }

    public string Controller { get; set; }
    public string Action { get; set; }

    public List<PropertyDefinition> Properties { get; set; }
}

public class PropertyDefinition
{
    public int PropertyDefinitionId { get; set; }
    public string Name { get; set; }
    public string Type { get; set; } // NormalString, LongString, XhtmlString, Number, TrueFalse
}

public class PropertyValues
{
    public int PropertyValueId { get; set; }
    public int PageId { get; set; }
    public int PropertyDefinitionId { get; set; }

    public string ValueNormalString { get; set; } // input=text
    public string ValueLongString { get; set; } // textarea
    public string ValueXhtmlString { get; set; } // tinymce
    public int ValueNumber { get; set; } // input=text
    public bool ValueTrueFalse { get; set; } // input=checkbox

    public PropertyDefinition Definition { get; set; }
}

Basically, when I’m in my View i want to be able to call for example

@Page.Property["Whatever"]

and get the values. I’m stuck with the above, and don’t know how to proceed.

Edit:

With some help from the answer I got from Russ, I came up with the following – which works.
Don’t know if there is any better solution to the problem.

Any one have any suggestions on how to improve my solution?

Models:

public class Page
{
    public int PageId { get; set; }
    public string Name { get; set; }

    public List<Property> Properties { get; set; }

    Dictionary<string, object> PageData = new Dictionary<string, object>();
    public object this[string name]
    {
        get
        {
            Property result = this.Properties.Find(
                delegate(Property p)
                {
                    return p.Name.Equals(name);
                });

            if (result != null)
            {
                switch (result.PropertyDefinition.Type)
                {
                    case "String":
                        return result.PropertyValue.ValueString;
                    case "LongString":
                        return result.PropertyValue.ValueLongString;
                    case "XHtmlString":
                        return result.PropertyValue.ValueXhtmlString;
                    case "Number":
                        return result.PropertyValue.ValueNumber;
                    case "Boolean":
                        return result.PropertyValue.ValueBoolean;
                    default:
                        return null;
                }
            }

            return null;
        }
        set
        {
            PageData[name] = value;
        }
    }
}

public class PropertyDefinition
{
    public int PropertyDefinitionId { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public string Type { get; set; }
}

public class PropertyValue
{
    public int PropertyValueId { get; set; }
    public int PropertyId { get; set; }

    public string ValueString { get; set; }
    public string ValueLongString { get; set; }
    public string ValueXhtmlString { get; set; }
    public int ValueNumber { get; set; }
    public bool ValueBoolean { get; set; }
}

public class Property
{
    public int PropertyId { get; set; }
    public string Name { get; set; }
    public string Caption { get; set; }

    public Page Page { get; set; }
    public PropertyDefinition PropertyDefinition { get; set; }
    public PropertyValue PropertyValue { get; set; }

    public int PageId { get; set; }
    public int PropertyDefinitionId { get; set; }
    public int PropertyValueId { get; set; }
}

Controller:

public class HomeController : Controller
{
    public String Index()
    {
        List<Property> properties = new List<Property>();
        Property propertyOne = new Property {
            PropertyId = 1,
            Name = "Title",
            Caption = "Page Title",
            TestPageId = 1,
            PropertyValue = new PropertyValue {
                PropertyValueId = 1,
                PropertyId = 1,
                ValueString = "This is the page title"
            },
            PropertyDefinition = new PropertyDefinition {
                PropertyDefinitionId = 1,
                Name = "String",
                Description = "String (< 255 characters)",
                Type = "String"
            }
        };
        properties.Add(propertyOne);

        Page CurrentPage = new Page
        {
            TestPageId = 1,
            Name = "Testpage",
            Properties = properties
        };


        return CurrentPage["Title"].ToString();
    }

}
  • 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-27T13:51:02+00:00Added an answer on May 27, 2026 at 1:51 pm

    Assuming that the model passed to the strongly typed View is of type Page, then it should simply be @Model.Properties. So your Razor view looks something like

    @* set the model for the view to be of type Page *@
    @model Page
    
    @* to get the properties *@
    @foreach(var prop in Model.Properties)
    {
        <p>@prop.PageId</p>
    }
    

    In order to index into Properties collection using a string, I’d recommend using a Dictionary<string, PropertyDefinition> instead of a List<PropertyDefintion>, or make it a KeyedCollection<TKey, TItem>.

    You might decide to create your own WebViewPage that adds a Page property by inheriting from System.Web.Mvc.WebViewPage and then setting this as the baseType in the web.config under the Views folder

    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <!-- Set your type here below -->
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
            <namespaces>
                <add namespace="System.Web.Mvc" />
                <add namespace="System.Web.Mvc.Ajax" />
                <add namespace="System.Web.Mvc.Html" />
                <add namespace="System.Web.Routing" />
                <add namespace="System.Web.Configuration"/>
                <add namespace="System.ComponentModel.DataAnnotations"/>
            </namespaces>
        </pages>
    </system.web.webPages.razor>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have some data like this: 1 2 3 4 5 9 2 6
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.