0

I have two classes:

public class DocumentViewModel
{
    public virtual string DocumentNumber { get; set; }
}

public class PurchaseOrderViewModel : DocumentViewModel
{
    [DisplayName("PO Number")]
    public override string DocumentNumber { get; set; }
}

And a view:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Onyx.Web.Models.PurchaseOrderViewModel>" %>

<strong><%: Html.LabelFor(i => i.DocumentNumber) %>:</strong> <%: Model.DocumentNumber %>

I expect that to render

<strong>PO Number:</strong> PO-12345

but it actually renders

<strong>DocumentNumber:</strong> PO-12345

Is there a way to get around this?

Matt Grande
  • 11,964
  • 6
  • 62
  • 89
  • I looked at the possible duplicate, but there was no resolution, plus it was asked back in March. I was hoping things may have changed. – Matt Grande Sep 02 '10 at 13:01
  • I tried the cast, no such luck :( Also, I can understand what's happening in the other question, since their base model has an attribute. In my example, only the child has the attribute assigned. – Matt Grande Sep 02 '10 at 13:04

1 Answers1

0

I've come up with a solution to my own problem. It's not perfect, but it's alright.

Since these are just ViewModels, there's not logic in them. So, I changed class DocumentViewModel to interface IDocumentViewModel and, voilà, problem solved.

I'd still like to get this working for inheriting classes, but that's more my stubbornness than any business case.

Matt Grande
  • 11,964
  • 6
  • 62
  • 89