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

  • Home
  • SEARCH
  • 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 3665382
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:45:17+00:00 2026-05-19T01:45:17+00:00

I have the following abstract class: public abstract class TemplateBase { public abstract string

  • 0

I have the following abstract class:

public abstract class TemplateBase
{
    public abstract string TemplateName { get; }
    public string RuntimeTypeName { get { return GetType().FullName; } }
    public abstract List<AreaContainer> TemplateAreas { get; }
}

then these 2 inherited classes:

public class SingleColumnTemplate : TemplateBase
{
    public override string TemplateName { get { return "Single column"; } }

    public AreaContainer CenterColumn { get; private set; }

    public SingleColumnTemplate()
    {
        this.CenterColumn = new AreaContainer("Middle");
    }

    private List<AreaContainer> templateAreas;

    public override List<AreaContainer> TemplateAreas
    {
        get
        {
            if (this.templateAreas == null)
            {
                this.templateAreas = new List<AreaContainer>() { this.CenterColumn };
            }

            return this.templateAreas;
        }
    }
}

and

public class TwoColumnTemplate : TemplateBase
{
    public override string TemplateName { get { return "Two column"; } }
    public AreaContainer LeftColumn { get; private set; }
    public AreaContainer RightColumn { get; private set; }

    public TwoColumnTemplate()
    {
        LeftColumn = new AreaContainer("Left");
        RightColumn = new AreaContainer("Right");
    }

    private List<AreaContainer> templateAreas;

    public override List<AreaContainer> TemplateAreas
    {
        get
        {
            if (this.templateAreas == null)
            {
                this.templateAreas = new List<AreaContainer>() { this.LeftColumn, this.RightColumn };
            }
            return this.templateAreas;
        }
    }
}

I also have this class that is my model for editing:

public class ContentPage
{
    public virtual int ContentPageId { get; set; }

    public virtual string Title { get; set; }

    public TemplateBase Template { get; set; }
}

Question:

for my ActionResults I have the following:

[HttpGet]
public ActionResult Edit()
{
    var row = new ContentPage();
    var template = new TwoColumnTemplate();        

    // Areas
    HtmlArea html_left = new HtmlArea();
    html_left.HtmlContent = "left area html content";

    HtmlArea html_right = new HtmlArea();
    html_right.HtmlContent = "right area html content";

    template.LeftColumn.Areas.Add(html_left);
    template.RightColumn.Areas.Add(html_right);

    row.Template = template;
    return View(row);
}

[HttpPost]
[ValidateInput(false)]
public ActionResult Edit(ContentPage row)
{
    // Here i could loop through List -TemplateAreas and save each template Area to Db. I guess that would work

    return this.View(row);
}

Question:

For HttpGet- how would I load row Template from the database? since it could be SingleColumnClass or TwoColumnClass.

how would my ViewModel look like to solve this?

thanks

  • 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-19T01:45:17+00:00Added an answer on May 19, 2026 at 1:45 am

    You need to know the template type in you controller, so you can pass a parameter from the view to the controller, indicating the type (SingleColumn or TwoColumn). You could do this witn a Enum:

    public enum TemplateType
    {
       SingleColumn,
       TwoColumn
    }
    
    [HttpGet]
    public ActionResult Edit(TemplateType templateType)
    {
        var row = new ContentPage();
        TemplateBase template; 
    
        if (templateType == TemplateType.SingleColumn)
        {
            template = new SingleColumnTemplate();
        }
        else
        {
            template = new TwoColumnTemplate();
        }
    
        ...
    
        return View(row);
    }
    

    When you create the action link from your view you can specify:

    <%= Html.ActionLink("Edit",
                        "Edit",
                        "YouController",
                        new 
                        { 
                            // singlecolumn or twocolumn
                            // depending on your concrete view
                            TemplateType = TemplateType.xxx 
                        },
                        null); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class: public abstract class AbstractParent { static String method() {
If have following class public abstract class MyBaseClass : BaseClass { public override string
I have following classes: public abstract class CustomerBase { public long CustomerNumber { get;
Lets say I have the following code: abstract class Animal case class Dog(name:String) extends
I have the following abstract classes: public abstract class AbSuperClass1<K,S> { //class definition }
I have the following abstract class which CAN NOT be changed. public abstract class
Within my code a have the following abstract superclass public abstract class AbstractClass<Type extends
I have following code: public abstract class TestProperty { public abstract Object PropertyValue {
I have following structure of my entities: @MappedSuperclass public abstract class BaseEntity { @Id
I have a question regarding the following code: abstract class a { public static

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.