about asp.net mvc 3 EditorTemplates using Csla.Core.BusinessBase

about asp.net mvc 3 EditorTemplates using Csla.Core.BusinessBase

Old forum URL: forums.lhotka.net/forums/t/10146.aspx


ohaiyo posted on Wednesday, March 09, 2011

/Views/Shared/EditorTemplates/Business.cshtml
@{
    if (ViewData.TemplateInfo.TemplateDepth > 1)
    {
        @(Model == null ? ViewData.ModelMetadata.NullDisplayText : ViewData.ModelMetadata.SimpleDisplayText)
    }
    else
    {
        var pms = ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit && !pm.IsComplexType && !ViewData.TemplateInfo.Visited(pm));
        foreach (var pm in pms)
        {
            if (pm.HideSurroundingHtml && pm.TemplateHint == "HiddenInput") {
                continue;
            }
            <div>
                @Html.Editor(pm.PropertyName)
            </div>
        }
    }
}

above EditorTemplates will generate all property of Csla.Core.BusinessBase.  but I just want generate property of model class.   

 

Now, my model class inherit GenericBusinessBase class  below, to not generate property of Csla.Core.BusinessBase in MVC 3 EditorTemplates.

 

    [Serializable]
    public abstract class GenericBusinessBase<T> : BusinessBase<T> where T : BusinessBase<T>
    {
        #region [ScaffoldColumn(false)]

        [ScaffoldColumn(false)]
        public override BrokenRulesCollection BrokenRulesCollection

        {
            get { return base.BrokenRulesCollection; }
        }

        #region ITrackStatus

        [ScaffoldColumn(false)]
        public new bool IsValid

        {
            get { return base.IsValid; }
        }

        [ScaffoldColumn(false)]
        public new bool IsSelfValid

        {
            get { return base.IsSelfValid; }
        }

        [ScaffoldColumn(false)]
        public new bool IsDirty

        {
            get { return base.IsDirty; }
        }

        [ScaffoldColumn(false)]
        public new bool IsSelfDirty

        {
            get { return base.IsSelfDirty; }
        }

        [ScaffoldColumn(false)]
        public new bool IsDeleted

        {
            get { return base.IsDeleted; }
        }

        [ScaffoldColumn(false)]
        public new bool IsNew

        {
            get { return base.IsNew; }
        }

        [ScaffoldColumn(false)]
        public new bool IsSavable

        {
            get { return base.IsSavable; }
        }

        [ScaffoldColumn(false)]
        public new bool IsChild

        {
            get { return base.IsChild; }
        }

        #endregion

        #region ITrackStatus

        [ScaffoldColumn(false)]
        public new bool IsBusy

        {
            get { return base.IsBusy; }
        }

        [ScaffoldColumn(false)]
        public new bool IsSelfBusy

        {
            get { return base.IsSelfBusy; }
        }

        #endregion

        #endregion
    }

 

 

So can add ScaffoldColumn(false) attribute to property of Csla.Core.BusinessBase? or have other solution? because I not want Create GenericBusinessBase<T> class .

RockfordLhotka replied on Wednesday, March 09, 2011

You should suggest to Microsoft that their template generation code should honor the Browsable(false) attribute that is already on those CSLA base class properties.

The Browsable attribute has been around since .NET 1.0, and is used by virtually every UI designer (and some data binding technologies) to do exactly what you want.

The fact that the MVC guys decided to invent a new attribute when one already existed is the problem here... Or at worst, they should support both - the original and their new one.

Copyright (c) Marimer LLC