data-annotations

Data Annotations not showing for partial Entity classes in MVC 4

这一生的挚爱 提交于 2019-12-21 20:47:10
问题 I have seen dozens of explanations of how to add metadata annotations, via partial classes, to classes generated via Entity Framework, database first . Can someone tell me why these new display values are not showing in my views? Both of these are part of the same namespace as my entity framework generated classes. [MetadataType(typeof(xRef_CodesMetadata))] public partial class xRef_Codes { } public class xRef_CodesMetadata { public int CodeID { get; set; } public int CTB_ID { get; set; }

Error message for Index data annotation in EF

家住魔仙堡 提交于 2019-12-21 17:06:04
问题 Hi I am using Entity Framework 6.1.1 which supports the Index data annotation feature in it. I have a field defined in my entity class as: [Index("scoreIndex", IsUnique=true)] public int score{ get; set; } This is working fine. However, I am trying to figure out how to display a message when the score is not unique. Right now it just throws an exception. I tried the following [Index("scoreIndex", IsUnique=true, ErrorMessage="Score must be unique")] But it does not contain the definition for

ASP.NET MVC Model/ViewModel Validation

这一生的挚爱 提交于 2019-12-21 16:58:47
问题 I have model classes in Linq-to-Sql with partial classes marked with data annotation attributes and a reference to xVal. When I bind a view directly to a model everything works great, both the JS generated by xVal and server side double check. Many of my views don't take input to one specific model, so I am setting up view model classes. Instead of exposing an entire model instance I expose properties into the model that I allow/need to be set by the view. // foo model public class Foo {

MV3 input validation - IE8 & IE9 behave differently

為{幸葍}努か 提交于 2019-12-21 06:25:47
问题 I'm using DataAnnotations to validate my input fields on a MVC3 application. I'm using regular expressions validations. I get the validation messages on the UI for IE8 & IE9. But I notice the difference when I hit the Save button even after the client side validation has failed. IE9 keeps me on the client side. On IE8 however, the control goes to the controller action, and I have to have a controller side TryValidateModel so that the validation errors out. Does anyone know why IE8 is doing a

How to use and/or localize DisplayAttribute with ASP.NET MVC2? [duplicate]

我的未来我决定 提交于 2019-12-21 05:35:38
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: DisplayName attribute from Resources? I am trying to figure out how to get the DisplayAttribute in my MVC 2 ViewModel to work with the Html.LabelFor() helper. Neither public class TestModel { [Display(ResourceType = typeof(Localization.Labels))] public string Text { get; set; } } nor public class TestModel { [Display(Name = "test")] public string Text { get; set; } } seem to work. Localizing the Required

Can't get Custom Attribute Value in MVC3 HTML Helper

£可爱£侵袭症+ 提交于 2019-12-21 05:05:23
问题 I've extended the HTML helper with a method that needs an attribute value from the property of the model. So I've defined a custom attribute as such. public class ChangeLogFieldAttribute : Attribute { public string FieldName { get; set; } } It's used like this in my model. [Display(Name = "Style")] [ChangeLogField(FieldName = "styleid")] public string Style { get; set; } In my helper method, I've got the following code to get the FieldName value of my attribute, if the attribute is used for

Custom Model Binder Not Validating Model

房东的猫 提交于 2019-12-21 04:08:57
问题 I started to play around with knockout.js and in doing so I used the FromJsonAttribute (created by Steve Sanderson). I ran into an issue with the custom attribute not performing model validation. I put together a simple example-- I know it looks like a lot of code-- but the basic issue is how to force the validation of the model within a custom model binder. using System.ComponentModel.DataAnnotations; namespace BindingExamples.Models { public class Widget { [Required] public string Name {

DataAnnotations “NotRequired” attribute

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-21 03:42:28
问题 I've a model kind of complicated. I have my UserViewModel which has several properties and two of them are HomePhone and WorkPhone . Both of type PhoneViewModel . In PhoneViewModel I have CountryCode , AreaCode and Number all strings. I want to make the CountryCode optional but AreaCode and Number mandatory. This works great. My problem is that in the UserViewModel WorkPhone is mandatory, and HomePhone is not. Is there anyway I can dissable Require attributs in PhoneViewModel by setting any

Why is DataAnnotations <Display(Name:=“My Name”)> ignored when using a DataGrid with AutoGenerateColumns=“True”

自闭症网瘾萝莉.ら 提交于 2019-12-20 14:24:54
问题 I'm using the WPF DataGrid to bind to a collection of a custom class. Using AutoGenerateColumns="True" in the grid XAML, the grid is created and populated just fine, but the headings are the property names, as one would expect. I tried specifying <Display(Name:="My Name")> from the System.ComponentModel.DataAnnotations namespace and that has no effect. I also tried <DisplayName("My Name")> from the System.ComponentModel name space but still the headings are not affected. Is there no way to

Why is DataAnnotations <Display(Name:=“My Name”)> ignored when using a DataGrid with AutoGenerateColumns=“True”

ε祈祈猫儿з 提交于 2019-12-20 14:24:19
问题 I'm using the WPF DataGrid to bind to a collection of a custom class. Using AutoGenerateColumns="True" in the grid XAML, the grid is created and populated just fine, but the headings are the property names, as one would expect. I tried specifying <Display(Name:="My Name")> from the System.ComponentModel.DataAnnotations namespace and that has no effect. I also tried <DisplayName("My Name")> from the System.ComponentModel name space but still the headings are not affected. Is there no way to