.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

DataAnnotations [HiddenInput()]

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :ASP.Net

I am using [HiddenInput(DisplayValue = false )] but there is property called TypeId. Anyone used it?

Searched alot but couldn't find any useful use.


View Complete Post

More Related Resource Links

Which ComponentModel.DataAnnotations attributes are used in the Dynamic Data metadata classes?


This namespace contains a lot of attributes for use in, I'm sure, many different applications. I'm curious to know which subset of the attributes in this namespace can be and are used in the Dynamic Data proxy class system, where the entity class is given an attribute that specifies a metadata type. That type contains properties with the same names as properties in the entity class, and the metadata provider builds MetaColumns using attributes on properties in these 'buddy' (proxy') classes.

So far my list includes, from System.ComponentModel.DataAnnotations:

Required, Range, DisplayFormat, StringLength, UIHint, DataType, Regular Expression, Display Column, Editable, and CustomValidation.

And from System.ComponentModel:

DisplayName, Description, and DefaultValue.

Am I missing any?

This was originally asked by myself on StackOverflow at: http://stackoverflow.com/questions/3537356/which-componentmodel-dataannotations-attributes-are-used-in-the-dynamic-data-meta

DataAnnotations.Display.Order not working with MVC 2 (using Futures)

Hi All!I have these two classes in my model: public partial class Customer { #region Primitive Properties [Display(Name="Note", Order=10)] public virtual string Notes { get; set; } ... public partial class AdvisoryCentre : Customer { #region Primitive Properties [Display(Name="Denominazione", Order=-10)] public virtual string BusinessName { get; set; } ... In the editor for the AdvisoryCentre model, using Html.EditorForModel, the behavior is not what i expected. When creating a new AdvisoryCentre object, BusinessName and Notes fields are shown in correct order, but when i edit an existing AdvisoryCentre with empty Notes property, the Notes field is always shown before BusinessName field. If Notes property is not empty, the fields order is correct.There is a workaround for this problem?Thankyou

Validating ICollection using DataAnnotations

 What's the best way to validate ICollectionie. sample class: public class BlogPost    {        public BlogPost()        {            this.CreateDate = DateTime.Now;            this.IsPostNow = false;        }        public virtual int BlogPostId { get; set; }        public virtual int AdminId { get; set; }        public virtual ICollection<BlogCategory> BlogCategory { get; set; }    }what's the best way to ensure that at least ONE BlogCategory is selected (if on the edit page BlogCategory is a list of checkboxes)thanks

DataGrid DataAnnotations DisplayAttribute


Does the data annotations display attribute work with the WPF data grid?  I have tried it and it seems to be ignored.  Is there something special that has to be done to make it work?  They do work fine if I create a Silverlight application are they only for Silverlight?  I am using Visual Studio 2010 and .Net 4.  I'm posting here as searching on data annotations seems to lead to silverlight related pages rather than WPF related.  Thanks.


Using DataAnnotations to verify integer


I am using Entity Framework with partial classes added on so I can use DataAnnotation attributes.  Does anyone know how to add a data annotatin which will verify that a field is a whole number (or a DataType of int or long)?  I'm surprised there is no [DataType(DataType.Integer)] attribute.  I tried to create a custom attribute, but it doesn't work because the value it receives is always null:

[DataTypeWholeNumberAttribute(ErrorMessage = "Zip must be a whole number")]
public object Zip{ get; set; }

public class DataTypeWholeNumberAttribute : ValidationAttribute
    public override bool IsValid(object value)
       long i;

        if (value == null) //value is always null.
            return false;

        return Int64.TryParse(value.ToString(), out i);

Obviously I'm missing the point, but I don't know enough to know what I'm missing.  Can anyone shed some light?

[MVC2] Problem with DataAnnotations.Required



I have problem with use DataAnnotations.Required. In mode I have property:

                ErrorMessageResourceName = "UserNameRequired", ErrorMessageResourceType = typeof(Resources.Text)
        public string UserName

UserName is obligatory property. But in this version test:


Return always return True. When I change property to:

                ErrorMessage = "Nazwa uzytkownika jest pusta."
        public string UserName

ModelState.IsValid work OK.

I use MVC2 and .Net Framework 3.5. I do not understand why this is. Please help.

Grzegorz Wisniewski

Dynamically adding DataAnnotations outside of Global.asax... possible?


Is it possible to add/remove/edit System.ComponentModel.DataAnnotations (for example [Display(Name = "Foreign")] or [ScaffoldColumn(true)] ) AT RUNTIME, outside of Global.asax?   For example,  one user logs in and the column is shown the column name "Foreign", another logs in and the same column is named "Extranjero" and would NOT see the scaffolded DB column [USPriceInDollars].

I realize the MetaModel is registered at Application_Start(), but I would like to actually register the model on Login....

Any code samples or techniques appreciated.

DataAnnotations and Model MetaData Caching


My case:

I am developing an application that will run for multiple clients, each client  has the ability to customize field displays and error messages.

My issue:

I created some custom attributes which inherit from DisplayNameAttribute, RequiredAttribute etc... and in them I am pulling out the resource needed.

However it is only executed the once, so if my context changes it will be pulling the incorrectly cached value instead of pulling the new value need.

Has anybody attempted to try something like this with the data annotations? Or any advice such as just don't use them for this scenario?



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend