문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top