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 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

Related Questions

I am wondering if is possible to implement following domain model. Let's have a
I have a generic class which represents a fragment of text. That fragment of
I have a domain model specifying the interfaces or my domain and I'm using
I'm using the following approach to handle a FIFO queue based on Google App
I'm working with a model structure that is not exactly ideal (i.e. I didn't
Even though I know that, at least to my knowledge, this is not the
in one of my Django models I have to add specific code for each
What is the best practice for storing font information of labels in Cocoa-Touch following
I am developing a WPF Application using MVVM Architecture. I am an amateur in
I started to use silverlight/flex and immediately bumped into the asynchronous service calling. I'm

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.