data-annotations

Localizing MVC3 Validation Messages

这一生的挚爱 提交于 2019-12-10 13:37:00
问题 I'm trying to localize the validation messages of the data-annotations. I thought that it could be done as described here: Supporting ASP.NET MVC 3 Validation with Non-English Locales. Now it says that ASP.NET MVC and types in the System.ComponentModel.DataAnnotations namespace use their own localized messages. So is that more or less useless to me and only a help for formatting for example prices? But back to the real question, so the only way to localize the validation messages is doing

How are you meant to use Prompt, Description, Ordering when applying data-annotations in ASP.NET MVC 3

大城市里の小女人 提交于 2019-12-10 13:23:08
问题 I have a view model with a property on it that looks like this: [Display(Name = "Some Property", Description = "This is description", Prompt = "This is prompt")] [Required(ErrorMessage = RequiredFieldMessage)] public string SomeProperty { get; set; } But this does not seem to render anything extra in the view. Do you need to do some additional work? <div class="editor-label"> @Html.LabelFor(model => model.SomeProperty ) </div> <div class="editor-field"> @Html.TextAreaFor(model => model

CustomValidation attribute doesn't seem to work

一笑奈何 提交于 2019-12-10 13:22:47
问题 I have a simple test page in my Silverlight 4 application in which I'm trying to get a custom validation rule to fire. I have a TextBox and a Button, and I am showing the validation results in a TextBlock. My view model has a Name property, which is bound the the Text property of the TextBox. I have two validation attributes on the Name property, [Required] and [CustomValidation] . When I hit the Submit button, the Required validator fires correctly, but the breakpoint inside the validation

EmailAddressAttribute without being required

血红的双手。 提交于 2019-12-10 12:39:18
问题 I have a [EmailAddress] DataAnnotation from .net 4.5 on a model property, which returns a ' The Email field is not a valid e-mail address. ' error during validation, when the Email property is empty. While this is technically true, I would have expected this empty value to only be caught with a [Required] annotation. Is there any parameter I'm missing which can be passed to the [EmailAddress] annotation to allow empty strings to validate, or do I have to fall back to using a custom validator

Disable System.CompositionModel.DataAnnotation from generating db scema instead use it just for unobstrusive jquery validation

扶醉桌前 提交于 2019-12-10 12:24:35
问题 I want to use System.CompositionModel.DataAnnotation for building Model but it should not affect database schema for example if I am using Required then it should not make that column as not nullable in Database. The reason I want to use Data annotation is for MVC 4 JQuery Unobstrusive validation. As of Now I have applied validation by using @Html.TextBoxFor(model => model.BookingRequest.Email, new { data_val = "true", data_val_required = "Please provide Special Notes" }) I think this is not

where should I put the EF entity and data annotations in asp.net mvc + entity framework project

早过忘川 提交于 2019-12-10 12:16:56
问题 So I have a DataEntity class generated by EntityFramework4 for my sqlexpress08 database. This data context is exposed via a WCF Data Service/Odata to silverlight and win forms clients. Should the data entities + edmx file (generated by EF4) go in a separate class library? The problem here then is I would specify data annotations for a few entities and then some of them would require specific MVC attributes (like CompareAttribute) so the class library would also reference mvc dlls. There also

Entity Framework - Validation (server + clientside, jquery) with data annotations, WITHOUT MVC?

冷暖自知 提交于 2019-12-10 11:50:20
问题 there are several tutorials that explain how to use EF data annotation for forms validation using the MVC framework. And to use jquery for the client side. See e.g.: http://dotnetaddict.dotnetdevelopersjournal.com/clientvalidation_mvc2.htm I would like to achieve the same, but without using MVC/MVC2. I want to build a classic asp.net site, create the Entities Model, create my partial classes that include the validation (required, regex etc.). I created the entities model and the partial

ASP.NET MVC 4 Unobtrusive validation broken on complex models

安稳与你 提交于 2019-12-10 11:49:18
问题 Alright, so I have a model that looks like: public class CustomerViewModel { public string Password { get; set; } } public class CustomerAddViewModel { public CustomerViewModel Customer { get; set; } [System.ComponentModel.DataAnnotations.Compare("Customer.Password", ErrorMessage = "The confirm password should match")] public string ConfirmPassword { get; set; } } I get the error message "Could not find a property named Customer.Password" on validation. I found this SO Question, but it doesn

Why MVC Model Binder set required for int, long values?

冷暖自知 提交于 2019-12-10 10:59:39
问题 I have a Model Like this public int Id {get;set;} [Required] public string FirstName{get; set} [Required] public string LastName{get; set} The Id is auto generate in DB. when I want call Create action The ModelState says that "The Id field is required"!!!! I Found this for my problem but it not clean solution. Is there an other way to solve this? Is there a way that I change Mvc ModelBinder behavior for value types? 回答1: The best solution to this problem is to use a view model. A view model

Can I add MVC 2 DataAnnotation attributes to existing properties?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 10:26:39
问题 I'm using a generated class as a model, and I wish to add DataAnnotation attributes to some of its properties. As it's a generated code, I don't want to add the annotations directly. Is there another way to attach them to a property? I'd considered making the model an interface, and using a partial class to get the generated class to subscribe to it. Is there a less elaborate solution, assuming that would even work? 回答1: Yes there is. You have to create metadata class that will have the same