data-annotations

Greater Than or Equal To Today Date validation annotation in MVC3

不问归期 提交于 2019-12-17 17:49:07
问题 Has anyone seen an MVC3 data annotation for Date validation that requires a single selected date to be equal to or greater than current date? If there's already a third party add on that's cool too. I'm already using the DataAnnotationsExtensions but it doesn't offer what I'm looking for. There doesn't seem to be any reference of this on. So, hoping someone has already solved this before I try to reinvent the wheel and write my own custom validator. I've tried Range but that requires 2 dates

ASP.NET MVC datetime culture issue when passing value back to controller

假装没事ソ 提交于 2019-12-17 16:05:23
问题 How can i tell my controller/model what kind of culture it should expect for parsing a datetime? I was using some of this post to implement jquery datepicker into my mvc application. When i submit the date it gets "lost in translation" i'm not using the US formatting for the date, so when it gets sent to my controller it simply becomes null. I have a form where the user chooses a date: @using (Html.BeginForm("List", "Meter", FormMethod.Get)) { @Html.LabelFor(m => m.StartDate, "From:") <div>

ASP.NET MVC datetime culture issue when passing value back to controller

怎甘沉沦 提交于 2019-12-17 16:05:18
问题 How can i tell my controller/model what kind of culture it should expect for parsing a datetime? I was using some of this post to implement jquery datepicker into my mvc application. When i submit the date it gets "lost in translation" i'm not using the US formatting for the date, so when it gets sent to my controller it simply becomes null. I have a form where the user chooses a date: @using (Html.BeginForm("List", "Meter", FormMethod.Get)) { @Html.LabelFor(m => m.StartDate, "From:") <div>

mvc4 data annotation compare two dates

冷暖自知 提交于 2019-12-17 15:34:25
问题 I have these two fields in my model: [Required(ErrorMessage="The start date is required")] [Display(Name="Start Date")] [DisplayFormat(DataFormatString = "{0,d}")] public DateTime startDate { get; set; } [Required(ErrorMessage="The end date is required")] [Display(Name="End Date")] [DisplayFormat(DataFormatString = "{0,d}")] public DateTime endDate{ get; set; } I require that endDate must be greater than startDate . I tried using [Compare("startDate")] but this only works for the equal

Writing a CompareTo DataAnnotation Attribute

北慕城南 提交于 2019-12-17 09:59:47
问题 I have a situation where I want to compare to fields (example, ensuring the start time is before the end time). I'm using the System.ComponentModel.DataAnnotations attributes for my validation. My first thought was something like this: public enum CompareToOperation { EqualTo, LessThan, GreaterThan } public class CompareToAttribute : ValidationAttribute { CompareToOperation _Operation; IComparable _Comparision; public CompareToAttribute(CompareToOperation operation, Func<IComparable>

Validate data using DataAnnotations with WPF & Entity Framework?

*爱你&永不变心* 提交于 2019-12-17 07:07:31
问题 Is there any way to validate using DataAnnotations in WPF & Entity Framework? 回答1: You can use the DataAnnotations.Validator class, as described here: http://johan.driessen.se/archive/2009/11/18/testing-dataannotation-based-validation-in-asp.net-mvc.aspx But if you're using a "buddy" class for the metadata, you need to register that fact before you validate, as described here: http://forums.silverlight.net/forums/p/149264/377212.aspx TypeDescriptor.AddProviderTransparent( new

Remote Validation in ASP.Net MVC 3: How to use AdditionalFields in Action Method

萝らか妹 提交于 2019-12-17 05:53:13
问题 I've been using the new ASP.Net MVC 3 RemoteAttribute to send a remote call to an action method that had a single parameter. Now I want to pass in a second parameter using the AdditionalFields property: [Remote("IsEmailAvailable", "Users", AdditionalFields = "InitialEmail")] Where IntialEmail is a hidden field in the view. The action looks like so: public JsonResult IsEmailAvailable( string email, string InitialEmail) { //etc. } When the view is rendered, the hidden field is populated, but

How to retrieve Data Annotations from code? (programmatically)

天大地大妈咪最大 提交于 2019-12-17 03:34:08
问题 I'm using System.ComponentModel.DataAnnotations to provide validation for my Entity Framework 4.1 project. For example: public class Player { [Required] [MaxLength(30)] [Display(Name = "Player Name")] public string PlayerName { get; set; } [MaxLength(100)] [Display(Name = "Player Description")] public string PlayerDescription{ get; set; } } I need to retrieve the Display.Name annotation value to show it in a message such as The chosen "Player Name" is Frank. ==================================

How to retrieve Data Annotations from code? (programmatically)

吃可爱长大的小学妹 提交于 2019-12-17 03:34:02
问题 I'm using System.ComponentModel.DataAnnotations to provide validation for my Entity Framework 4.1 project. For example: public class Player { [Required] [MaxLength(30)] [Display(Name = "Player Name")] public string PlayerName { get; set; } [MaxLength(100)] [Display(Name = "Player Description")] public string PlayerDescription{ get; set; } } I need to retrieve the Display.Name annotation value to show it in a message such as The chosen "Player Name" is Frank. ==================================

Why won't my columns with Data Annotations map when using Entity Framework

梦想与她 提交于 2019-12-14 03:43:55
问题 I have a class that looks like this: public class Analyst { [Column("Internal_ID")] public int ID { get; set; } // if this is named like the column, it works [Column("DisplayName")] public string Name { get; set; } } This object is being filled like so (this next part is in a class which inherits from DbContext): public List<T> ExecProc<T>(string proc, Dictionary<string, object> params) { var parms = new List<SqlParameter>(); var sql = new StringBuilder(); sql.Append(sproc.StoredProcedure);