The problem is about TextFieldFor and subclass of System.ComponentModel.DisplayNameAttribute

  1. #1

    TextFieldFor generated C# Attribute code in view, How do I hide it

    Hello, my English is poor, but I will try to description the problem, Thank you for your patience.

    I have a problem about Html.X().TextFieldFor.

    there is the code which generated by ext.net mvc:

            Ext.net.ResourceMgr.init({isMVC:true,theme:"neptune"});
    Ext.onReady(function(){Ext.create("Ext.window.Window",{frame:true,hidden:false,renderTo:Ext.getBody(),width:600,autoScroll:true,items:[{xtype:"form",defaultAnchor:"95%",items:[{id:"Id",xtype:"hiddenfield",name:"Id",value:"00000000-0000-0000-0000-000000000000"},{id:"Name",
    
    
    
    bitResourceDisplayName:{
    "ResourceKey":"Admin.Configuration.Languages.Fields.Name",
    "DisplayName":"Name",
    "Name":"BitResourceDisplayName",
    "TypeId":"Bit.Web.Framework.BitResourceDisplayNameAttribute, Bit.Web.Framework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
    },
    
    
    
    xtype:"textfield",fieldLabel:"Name",name:"Name",allowBlank:false,blankText:"Required"}

    In this code, you can see a bitResourceDisplayName property - which is defined as a C# attribute.

    Now, i want hide the bitResourceDisplayName property in json, how can i do it?

    There is the C# code:


        public interface IModelAttribute
        {
            string Name { get; }
        }
    
        public class BitResourceDisplayNameAttribute : System.ComponentModel.DisplayNameAttribute, IModelAttribute
        {
            private string _resourceValue = string.Empty;
            //private bool _resourceValueRetrived;
    
            public BitResourceDisplayNameAttribute(string resourceKey)
                : base(resourceKey)
            {
                ResourceKey = resourceKey;
            }
    
            public string ResourceKey { get; set; }
    
            public override string DisplayName
            {
                get
                {
                    return "Name";
                }
            }
    
            public string Name
            {
                get { return "BitResourceDisplayName"; }
            }
        }



    and, I write a viewmodel ,it have lots of property and the property has a attribute of BitResourceDisplayNameAttribute, like this


    public class TestModel
    {
    
    [BitResourceDisplayName("Admin.Languages.Fields.Name")]
    [AllowHtml]
    public string Name { get; set; }
    
    
    [BitResourceDisplayName("Admin.Languages.Fields.Id")]
    [AllowHtml]
    public string Id { get; set; }
    
    }
    this is the view

        @model TestModel 
    
        @(Html.X().ResourceManager()
        .ShowWarningOnAjaxFailure(true))
    
    @(
       X.Window()
        .Title("Check/Radio Groups Example")
        .Frame(true)
        .Width(600)
        .BodyPadding(10)
        .Items(
            X.FormPanel().Items(
                X.HiddenFor(p => p.Id),
                X.TextFieldFor(p => p.Name)
            )
            .Layout(LayoutType.Anchor)
            .DefaultAnchor("95%")
            .FieldDefaults(fd =>
            {
                fd.LabelSeparator = ":";
                fd.LabelWidth = 140;
                fd.LabelStyle = "padding-left:4px;";
                fd.MsgTarget = MessageTarget.Side;
            })
        )
    )
    thanks!!!
    Last edited by macroe; Dec 24, 2013 at 4:14 PM.

Similar Threads

  1. [CLOSED] Custom TextFieldfor helper
    By infonext in forum 2.x Legacy Premium Help
    Replies: 7
    Last Post: Jan 09, 2014, 4:25 AM
  2. [CLOSED] How to subclass RadioGroup labels?
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jan 26, 2013, 7:46 PM
  3. Replies: 4
    Last Post: Feb 01, 2011, 11:54 AM
  4. Subclass Ext.NET v1.0
    By mtpanissa in forum 1.x Help
    Replies: 0
    Last Post: Jun 25, 2010, 8:58 PM
  5. Replies: 2
    Last Post: Aug 31, 2009, 6:03 PM

Posting Permissions