model-validation

Auto generating metadata classes for Entity Framework

I am considering using xVal for validation of Entity Framework classes in a MVC application. This involves writing metadata classes as explained in details by Graham O'Neale (http://goneale.com/2009/03/04/using-metadatatype-attribute-with-aspnet-mvc-xval-validation-framework). I am wondering if there's a way to auto generate such metad...

Rails and Model Validation

I want to put some model level validation on the following table: create_table :audios do |t| t.integer :library_id, :null => false t.string :file, :null => false, :limit => 2048 t.string :name, :limit => 512 t.timestamps end Does this mean, that my model, which (so far) looks like: class Audio < ActiveRecord::Base belongs_...

Model validation with enumerable properties in Asp.net MVC2 RTM

I'm using DataAnnotations attributes to validate my model objects. My model class looks similar to this: public class MyModel { [Required] public string Title { get; set; } [Required(ErrorMessage = "At least one editor is required.")] public List<User> Editors { get; set; } } public class User { public int Id { get...

Unit Testing (xUnit) an ASP.NET Mvc Controller with a custom input model?

I'm having a hard time finding information on what I expect to be a pretty straightforward scenario. I'm trying to unit test an Action on my ASP.NET Mvc 2 Controller that utilizes a custom input model w/ DataAnnotions. My testing framework is xUnit, as mentioned in the title. Here is my custom Input Model: public class EnterPasswor...

Html.hiddenfor does not return value

Hi I have a template partial view, which used to render a model named VerificationCode, this model has a element 'CaptchaGeneratedText' which is hidden in the view and set value by Html.HiddenFor(m=>m.CaptchaGeneratedText, captchaText), the problem is when view post, in the model validation the value of element 'CaptchaGeneratedText...

ValidateModel Problem with DataAnnotations

I have a SearchViewModel with these properties: [RegularExpression("name")] public String SortField; [RegularExpression("asc|desc")] public String SortDirection; As you can see, I want "name" to be the only valid value of SortField at this time, and "asc" or "desc" the only valid values for SortDirection. However, Va...

Detect whether or not a specific attribute was valid on the model

Having created my own validation attribute deriving from System.ComponentModel.DataAnnotations.ValidationAttribute, I wish to be able to detect from my controller, whether or not that specific attribute was valid on the model. My setup: public class MyModel { [Required] [CustomValidation] [SomeOtherValidation] public st...

Marking a Field as Required

If I have a dbml file that contains say a Customer class with say a single property of CompanyName; public partial class Customer : INotifyPropertyChanging, INotifyPropertyChanged private string _CompanyName; public string CompanyName { get Now, given that the above is in a dbml and thus generated I obviously should avoid editing it...

ASP.NET MVC 2 Model Validation (DataAnnotations) on Subobject

Does the ASP.NET MVC 2 model validation includes subobjects? I have an instance "Filter", from this class: public class Filter { [StringLength(5)] String Text { get; set; } } in my main object: public class MainObject { public Filter filter; } However, when I do TryValidateModel(mainObject) the validation still works o...

How to use Html.CheckBox (list) with IEnumerable<T> with validation

Im working on a page where the user needs to fill in some information and finally make a selection of 1 or more customers with checkboxes. The list of customers is an IEnumerable<Customer> which i pass into my Model. Im a bit puzzled how i would go about creating the list of checkboxes using .CheckBoxFor(). And finally i would like to...

ASP.Net MVC 2 Model Validation Regex Validator fails

I have following property in my Model Metadata class: [Required(ErrorMessage = "Spent On is required")] [RegularExpression(@"[0-1][0-9]/[0-3][0-9]/20[12][0-9]", ErrorMessage = "Please enter date in mm/dd/yyyy format")] [DataType(DataType.Date)] [DisplayName("Spent On")] public DateTime SpentOn { get; set; } But whenever I call Mod...

Best way to handle multiple form validation in ASP.NET MVC

Overview I have a payment page where I allow the user to select a payment method, either credit card or check. I have a form for each of these payment methods. I did not want to create a separate page for each of these methods for UI purposes, so I use a [div] for each form and toggle their display with jQuery. Problem Each of the pa...

django manytomany validation

Please see the code below. Basically, when the user creates an object of this class, they need to specify the value_type. If value_type==2 (percentage), then percentage_calculated_on (which is a CheckboxSelectMultiple on the form/template side needs to have one or more items checked. The model validation isn't allowing me to validate lik...