Dec 24, 2013, 4:03 PM
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:
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:
and, I write a viewmodel ,it have lots of property and the property has a attribute of BitResourceDisplayNameAttribute, like this
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.