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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:57:25+00:00 2026-05-16T07:57:25+00:00

How would you implement this ? I have the following model : class Something

  • 0

How would you implement this ?

I have the following model :

class Something
{
     public string Label { get; set; }
     public DateTime Date1 { get; set; }
}

class SomethingStage2 : Something
{
     public DateTime Date2 { get; set; }
}

class SomethingStage3 : SomethingStage2
{
     public DateTime Date3 { get; set; }
}

And the following editor templates :

EditorTemplates\Something

<%@ Control Language="C#" Inherits="ViewUserControl<Something>" %>
<%= Html.Hidden( "TypeName", Model.GetType() ) %>
<%= Html.EditorFor( x => x.Label ) %>
<%= Html.EditorFor( x => x.Date1 ) %>

EditorTemplates\SomethingStage2

<%@ Control Language="C#" Inherits="ViewUserControl<SomethingStage2>" %>
<% Html.RenderPartial("EditorTemplates/Something.ascx" %>
<%= Html.EditorFor( x => x.Date2 ) %>

EditorTemplates\SomethingStage3

<%@ Control Language="C#" Inherits="ViewUserControl<SomethingStage3>" %>
<% Html.RenderPartial("EditorTemplates/SomethingStage2.ascx" %>
<%= Html.EditorFor( x => x.Date3 ) %>

For updating, I have the following controller method :

public ActionResult Update( Something model );

Technically, it works very well.

Update : for handling the different subclasses of the model, I’ve borrowed this idea :
http://www.codinginstinct.com/2010/03/aspnet-mvc-and-convention-based-forms.html

public class CustomModelBinder : DefaultModelBinder
{
    public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        var typeName = bindingContext.ValueProvider.GetValue("TypeName");
        var type = Type.GetType(reportFormTypeName.AttemptedValue);
        var model = bindingContext.ModelMetadata.Model;
        bindingContext.ModelMetadata = new ModelMetadata(ModelMetadataProviders.Current, 
            bindingContext.ModelMetadata.ContainerType,
            () => model, type , bindingContext.ModelMetadata.PropertyName);

        return base.BindModel(controllerContext, bindingContext);
    }
}

Update : If Date3 should go between Label and Date1, this approach won’t work, of course. That’s why it is for simple forms. And it is a big time saver,

Is this approach correct, for simple cases, where edit forms are straightforward ? I’m just wondering if it is “right” to do it this way. If not, how would you implement this ?

  • 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-16T07:57:26+00:00Added an answer on May 16, 2026 at 7:57 am

    There is one problem you will run in to.

    In your action: public ActionResult Update( Something model ); if you call UpdateModel(model) only the fields in the base class will be bound.
    For example, if model is a SomethingStage2 Label and Date1 will be bound but Date2 will not.

    This is because Try/UpdateModel operates on the compile time type and not the runtime type.
    I ran into this issue as well. I posted the solution here:
    MVC 2 UpdateModel on Interface, Should ModelBinderAttribute be ignored?

    (I’m assuming the missing closing parens in all of your Html.EditorFor statements are typos)

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

Sidebar

Ask A Question

Stats

  • Questions 496k
  • Answers 496k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer One area which you are not clear about is this:… May 16, 2026 at 11:40 am
  • Editorial Team
    Editorial Team added an answer Try it out: http://jsfiddle.net/WZ2Vk/ (Requires jQuery 1.4 or later) var… May 16, 2026 at 11:40 am
  • Editorial Team
    Editorial Team added an answer The built-in DOM inspectors in most modern browsers would be… May 16, 2026 at 11:40 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following class which I'm fighting over how to implement. The question
I am a noob in using model/view paradigm in Qt and have the following
I have a blog-like application with stories and categories: class Category(models.Model): ... class Story(models.Model):
I have a domain model that is trivially represented by the following. IMyInterface ClassA
I want to model an article with revisions in Django: I have following in
I have an library of scripts I would like to implement on the client
According to the cakebook section on the Auth component , I can implement simple
Say you have a customer object and the customer file form that manipulates that
What I would like to do (in C++) is create a 'Parameter' data type
I am trying to implement a histogram equalization method (HE) for a UIImage in

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.