data-annotations

Localization of data annotations in separate class library

别来无恙 提交于 2020-01-04 03:39:21
问题 We are trying to implement localization for our domain models which are existing in a separate class library project within our solution. However, we are not able to get it working as our models data annotation attributes doesn't get translated at all. Project structure Solution Web project Resource folder (Contains .resx files. Ex. App.en.resx ) Works fine Class library Domain models Resource folder (Contains .resx files. Ex. App.en.resx ) Doesn't work Startup.cs services.AddMvc()

Why isn't AutoFixture working with the StringLength data annotation?

为君一笑 提交于 2020-01-03 21:01:56
问题 I'm trying again to upgrade to AutoFixture 2, and I'm running into a problem with the data annotations on my objects. Here's an example object: public class Bleh { [StringLength(255)] public string Foo { get; set; } public string Bar { get; set; } } I'm attempting to create an anonymous Bleh , but the property with the annotation is coming up empty rather than being populated with an anonymous string. [Test] public void GetAll_HasContacts() { var fix = new Fixture(); var bleh = fix

xVal, DataAnnotations on the entire class

二次信任 提交于 2020-01-03 17:26:29
问题 I have a complete validation on an obeject and am trying to figure out the best way to handle it. Given the following class: public class LetterResponse { public Guid Id {get;set;} public bool SendBlankCart {get;set;} public string ToName {get;set;} public string ToAddress {get;set;} } I want to use a dataannotation and xval in order to validate the class before I persist it, but I have complex validation that requires more than one property. Pseudo: if SendBlankCart { - no validation on

xVal, DataAnnotations on the entire class

百般思念 提交于 2020-01-03 17:25:39
问题 I have a complete validation on an obeject and am trying to figure out the best way to handle it. Given the following class: public class LetterResponse { public Guid Id {get;set;} public bool SendBlankCart {get;set;} public string ToName {get;set;} public string ToAddress {get;set;} } I want to use a dataannotation and xval in order to validate the class before I persist it, but I have complex validation that requires more than one property. Pseudo: if SendBlankCart { - no validation on

mvc DataAnnotations how to make field no editable in 3.5

六月ゝ 毕业季﹏ 提交于 2020-01-03 06:18:53
问题 I have a few field in my entity that i wish to be non-editable. Looking in the docs it seems like "EditableAttribute" would do the trick. However this is only 4.0 Just wondering if there are other attributes that would have the desire effect. So be clear, i have a field called "DateRegistered" i wish to display this as string not text field using "Html.EditorFor" 回答1: The [ReadOnly] attribute should work in 3.5. 回答2: Why are you using an editor template for something that should be read only?

step by step problem with validation on “back” button

坚强是说给别人听的谎言 提交于 2020-01-02 20:03:27
问题 I have a 3 steps forms where I bind for each step on a ViewModel that has DataAnnotation. Everything works fine except that when I click on my "previous" button, the validation gets called and, if there's missing values, the user has to fill all required fields. If I go with an action link, then the data won't be persisted. What I'm looking for here is a way to save my values without calling the validation. I also consider using cookies but I don't think that it's the best way of doing it.

MVC3 Attribute validation question

房东的猫 提交于 2020-01-02 19:18:09
问题 I'm getting odd behavior with my validation in my view. My model has this property. [Display(Name = "Overflow Capacity")] [RegularExpression(@"[-+]?[0-9]*\.?[0-9]?[0-9]", ErrorMessage = "Number required.")] [Range(0,9999.99,ErrorMessage = "Value must be between 0 - 9,999.99")] public decimal OverFlowCapacity { get; set; } My view has this: <tr> <td>@Html.LabelFor(m=> m.OverFlowCapacity)</td> <td>@Html.EditorFor(m=>m.OverFlowCapacity)</td> <td> @Html.ValidationMessageFor(model => model

Why does EF Code First [InverseProperty] attribute fail to work when used with [ForeignKey] attribute?

自作多情 提交于 2020-01-02 07:13:26
问题 Using: EF 4.3.1, Visual Studio 2010, SQL CE 4.0 My understanding is that when declaring Foreign Keys with DataAnnotation in EF, it can be done either of the following ways: Option 1- [ForeignKey("Player1Home")] public long? HPlayer1Id { get; set; } public virtual Player Player1Home { get; set; } Option 2- public long? HPlayer1Id { get; set; } [ForeignKey("HPlayer1Id")] public virtual Player Player1Home { get; set; } Problem: When the InverseProperty DataAnnotation gets used with Option 2 an

how to validate a property according to another property in DataAnnotation

笑着哭i 提交于 2020-01-02 05:32:09
问题 Consider I have a these two properties: public class Test { [Required(ErrorMessage = "Please Enetr Age")] public System.Int32 Age { get; set; } [Required(ErrorMessage = "Choose an option")] public System.Boolean IsOld { get; set; } } When the user enters for example 15 for Age and choose " Yes " for IsOld , I return an exception that correct Age or IsOld . I've used CustomValidation for it, but because my my validation must be static I can't access to other properties. How can I do this by a

Client-side validation does not work when inherting from RequiredAttribute in ASP.NET MVC 3?

帅比萌擦擦* 提交于 2020-01-02 04:34:09
问题 I created an inherited attribute like this in ASP.NET MVC3: public sealed class RequiredFromResourceAttribute : RequiredAttribute { public RequiredFromResourceAttribute(string errorResourceName, string errorResourceTypeName) { this.ErrorMessageResourceName = errorResourceName; this.ErrorMessageResourceType = Type.GetType(errorResourceTypeName); } } And use it like this: [RequiredFromResource("Title", "Resources.Resource, MyProject.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]