dataannotations

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...

Using EF POCO classes as MVC 2 models (with data annotations)

I have a 4 layered web application programmed in C#... .Net 4.0: UI Layer Business Layer Data access Layer Entities layer My data layer contains an edmx My entities layer contains my POCO objects (generated by a t4 script), and that layer is referenced in all other layers. When creating an MVC form to create a new customer, for exam...

DataAnnotations jQuery validation in asp.net mvc 2

Hi, I trying to use jQuery validation plugin with DataAnnotations in asp.net mvc 2 final. Now I'm using MicrosoftMvcValidation.js and it works. But I can't find way to work with jQuery validation. I read about MicrosoftMvcJQueryValidation.js. But I think that it is obsolete. How can I use DataAnnotations with jQuery validation plugin? ...

ASP.NET MVC EnableClientValidation

Does this <% Html.EnableClientValidation(); %> really enable client validation that validation without page refresh or not? The thing is that it is doing a page refresh while returning formviewmodal ,it is working fine when using modal ? So how will i make it work using formviewmodal here is the code of the controller returning FormVie...

Data-annotation getting errormessage out database

Hello, With asp.net mvc you can use the annotation [Required (errormessage="This is required")] How can I create something like this: [Required (errormessage="ERRORXX")] So I can look up in a database what this ERRORXX is and display it on my form. Now my form displays ERRORXX. How can I create something that solves my problem? Th...

How can I highlight empty fields in ASP.NET MVC 2 before model binding has occurred?

I'm trying to highlight certain form fields (let's call them important fields) when they're empty. In essence, they should behave a bit like required fields, but they should be highlighted if they are empty when the user first GETs the form, before POST & model validation has occurred. The user can also ignore the warnings and submit the...

MVC2 DataAnnotations on ViewModel - Don't understand using it with MVVM pattern

I have an MVC2 Application that uses MVVM pattern. I am trying use Data Annotations to validate form input. In my ThingsController I have two methods: [HttpGet] public ActionResult Index() { return View(); } public ActionResult Details(ThingsViewModel tvm) { if (!ModelState.IsValid) return View(t...

Support for nested model and class validation with ASP.NET MVC 2.0

I'm trying to validate a model containing other objects with validation rules using the System.ComponentModel.DataAnnotations attributes was hoping the default MVC implementation would suffice: var obj = js.Deserialize(json, objectInfo.ObjectType); if(!TryValidateModel(obj)) { // Handle failed model validation. } The object is com...

Add LINQ Auto-Generated Value Marker [Column(IsDbGenerated=true)] in Buddy Class

Hello, is it possible to decorate a field of a LINQ generated class with [Column(IsDbGenerated=true)] using a buddy class (which is linked to the LINQ class via [MetadataType(typeof(BuddyMetadata))]) ? My goal is to be able to clear and repopulate the LINQ ORM designer without having to set the "Auto Generate Value" property manually ev...

Do Buddy Classes only work for DataAnnotations?

Do buddy classes only work for dataannotations, or for any attribute? I've been trying to attach a ColumnAttribute to a field in my buddy class, but it appears that it doesn't get processed in the original class. The two classes are linked via MetadataType. ...

'ErrorMessageResourceType' property specified was not found. on XmlSerialise

In my ASP.Net MVC app I have a Model layer which uses localised validation annotations on business objects. The code looks like this: [XmlRoot("Item")] public class ItemBo : BusinessObjectBase { [Required(ErrorMessageResourceName = "RequiredField", ErrorMessageResourceType = typeof(StringResource))] [HelpPrompt("ItemNumber")] ...

Data Annotations on ViewModels or Domain Objects

Where would data annotations be more suitable: ViewModels or Domain Objects or Both I am struggling to decide where these will be more suited. I have not as yet fully utilized them but this question came to mind. From most of the examples I have seen, they are generally placed on Models and simply use the required attributes for va...

ASP.NET MVC DataAnnotations different table. Can it be done?

i have a language table which is as a foreign key in the link table , The link can be in 3 languages meaning there will be 3 rows in the link table every time i enter the record . i am using jQuery tabs to enter the records in 3 languages . OK so that thing is that there will be three text boxes for every field in the table.link name fie...

Context dependent validation

I would like to be able to validate an object in different contexts using DataAnnotations in .NET 4. For example: If I have a class with these annotated properties [Required] public string Name { get; set; } [Required] public string PhoneNumber { get; set; } [Required] public string Address { get; set; } I would like to be able to ...

How do I use server side validation with an AJAX post?

In his blog post, Scott Guthrie describes how to enable validation using DataAnnotations. Example: public class Product { [Display(Name="Product Number")] [Range(0, 5000)] public int ProductID { get; set; } [Display(Name="Name")] [Required] public string ProductName { get; set; } [Display(Name="Price")] ...

Using ASP.Net MVC Data Annotation outside of MVC

Hi there, i was wondering if there is a way to use ASP.Net's Data annotation without the MVC site. My example is that i have a class that once created needs to be validated, or will throw an error. I like the data annotations method, instead of a bunch of if blocks fired by the initaliser. Is there a way to get this to work? I though...

Property-level validation errors hinder the validation of Class-level validation

Update after Bounty was awarded A new solution is coming up to this problem. Please refer to ASP.NET MVC 3 Preview 1 here: http://weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx Look in the section Validation Model improvements, where you will see the solution to my problem. Original Post Referri...

DataAnnotations over WCF

I'm sending a DTO over wire (WCF) which has on one property the DisplayName atribute from System.ComponentModel and on a other one the ScaffoldColumn attribute. On the client I have a ASP.NET MVC 2 app and I use the Html.EditorFor(x=>x.DTO) extension method.When the page is rendered it looks like the attributes wasn't there. The DTO [S...

ASP.NET Validation not firing even when my form is obviously invalid.

I've got the following View <% Using Html.BeginForm()%> <%: Html.ValidationSummary(True) %> <div class="displayright"> <h3> <%: Html.LabelFor(Function(model) model.About) %></h3> <noscript> <h3> Please use <%: Html.ActionLink("Markdown", "Markdow...

Required Attribute in DataAnnotations Does Not seem to work

I have a DataAnnotationValidator that I created. I am currently trying to test it with a Required Field attribute and I can't get the IsValid property to fail when my property is null. It does work correctly when I create a number with a Range attribute that is outside of the specified Range. public class TestEntityWithDataAnnotations {...