I really need a second set of eyes, so I hope some of you can give me some feedback, I think I looked at it for too long.
I am trying to customize a website using ASP.NET MVC3, and on this site I need the flexibility to create dynamic objects. But I mean that in my database there are a number of tables that store information about the structure and the data contained in these dynamic objects. I work with an existing database, so I am limited (to a certain extent) by what I can change. When I query the database for a dynamic object (not a .NET 4.0 dynamic object), I pass in my identifier, and what I get is a simple object, maybe a few properties for internal use only, and a property that represents a set containing all the properties for my dynamic object. Therefore, if my dynamic object was for a person with a name, DoB and Sex, my collection will have three objects,one for each property. This allows the site administrator to add new fields at runtime, and the website will automatically display them, allow updates, etc. Now I have a model binding, currently working for both mapping and postback for this data structure. For each object in the collection, I visualize two pieces of data, a unique property identifier (which is currently a hidden field, and Id is a landmark) and the property value. My problem is the security aspect.and for postback for this data structure. For each object in the collection, I visualize two pieces of data, a unique property identifier (which is currently a hidden field, and Id is a landmark) and the property value. My problem is the security aspect.and for postback for this data structure. For each object in the collection, I visualize two pieces of data, a unique property identifier (which is currently a hidden field, and Id is a landmark) and the property value. My problem is the security aspect.
If I were dealing with strongly typed objects, I could create custom ViewModels and execute with it or add Bind () attributes to the action signature, but since the properties of these objects are flexible collections, I’m not sure how to approach it. the steps are simple enough, I can create a custom Authorize attribute and query the database for permissions, but I need to be able to restrict the behavior of collections to display and accept information based on user rights. For example, if I need to add a social security number property to a person’s object, I don’t want it to appear on the screen for certain people. But since a property is something that can change at runtime, so are permissions.
That's where I am as far as my thoughts go ...
, , , .
, , ViewModel DisplayTemplate, , . - ModelBinder, Html.Display() Html.Editor() ModelBinder.
postbacks. , , Guid . , , , , , . , MetaData, , , , , , , , , IsValid, , .
MetaData Html.Display() Html.Editor() , , , .
, MVC, , ModelBinders ModelMetaDataProviders ModelValidationProviders.
, , , , , , , Google .
EDIT: . ,
EDIT: . ModelMetadataProvider.
public override ModelMetadata GetMetadataForProperty(Func<object> modelAccessor, Type containerType, string propertyName)
{
ModelMetadata metadata;
if (containerType == typeof(PseudoObjectAttributeViewModel))
{
switch (propertyName)
{
case "StringValue":
metadata = new ModelMetadata(this, typeof(PseudoObjectAttribute), modelAccessor, typeof(string), propertyName);
break;
case "DateValue":
metadata = new ModelMetadata(this, typeof(PseudoObjectAttribute), modelAccessor, typeof(DateTime?), propertyName);
break;
case "DoubleValue":
metadata = new ModelMetadata(this, typeof(PseudoObjectAttribute), modelAccessor, typeof(double?), propertyName);
break;
case "LongValue":
metadata = new ModelMetadata(this, typeof(PseudoObjectAttribute), modelAccessor, typeof(long?), propertyName);
break;
case "BooleanValue":
metadata = new ModelMetadata(this, typeof(PseudoObjectAttribute), modelAccessor, typeof(bool?), propertyName);
break;
case "GuidValue":
metadata = new ModelMetadata(this, typeof(PseudoObjectAttribute), modelAccessor, typeof(Guid?), propertyName);
break;
default:
return defaultMetadataProvider.GetMetadataForProperty(modelAccessor, containerType, propertyName);
break;
}
DataAnnotationsModelMetadata daMetadata = (DataAnnotationsModelMetadata)metadata;
System.Reflection.FieldInfo container = modelAccessor.Target.GetType().GetField("vdi");
AddSupplimentalMetadata(daMetadata, (PseudoObjectAttributeViewModel)((System.Web.Mvc.ViewDataInfo)container.GetValue(modelAccessor.Target)).Container);
}
else
metadata = defaultMetadataProvider.GetMetadataForProperty(modelAccessor, containerType, propertyName);
return metadata;
}
, GetMetadataForType(), .NET , , . ( teplate , , , , ).
Html.Editor(Model.PseudoObjectStructure.PseudoObjectControl.DataType)
, , , .
switch, . , MVC2 GetMetadataForProperty() propertyName, Func<object>, , MVC . , . , , , Reflection. , , . , , , - , AddSupplimentalMetadata(), DataAnnotationsModelMetadata, MVC .
. , , LINQ - nautre. - Display/EditorTemplate. , , .