string errorMessage = this.FormatErrorMessage(metadata. The problem I am getting here is I am using a jQuery dialog, and want to get validations on the client side on my dialog. a phone number, the ASP.NET MVC can supply you with basic validation out of the box. public IEnumerable GetClientValidationRules(ModelMetadata metadata, ControllerContext context) If your string falls into a specific category, e.g. ![]() Return new ValidationResult(base.ErrorMessage) (operatorname = GenericCompareOperator.LessThanOrEqual & valThis.CompareTo(valOther) > 0)) If ((operatorname = GenericCompareOperator.GreaterThan & valThis.CompareTo(valOther) = 0) || Var valOther = (IComparable)basePropertyInfo.GetValue(validationContext.ObjectInstance, null) Var basePropertyInfo = (CompareToPropertyName) String operstring = (OperatorName = GenericCompareOperator.GreaterThan ? "greater than " : (OperatorName = GenericCompareOperator.GreaterThanOrEqual ? "greater than or equal to " : (OperatorName = GenericCompareOperator.LessThan ? "less than " : (OperatorName = GenericCompareOperator.LessThanOrEqual ? "less than or equal to " : "")))) using System. To add a attribute in this case Required. Protected override ValidationResult IsValid(object value, ValidationContext validationContext) Adding data annotation to this - if we modify this model directly, when a update to the model is made, the changes are lost. Private GenericCompareOperator operatorname = GenericCompareOperator.GreaterThanOrEqual Public sealed class GenericCompareAttribute : ValidationAttribute, IClientValidatable if how can I implement IClientValidatable interface which I must need. Since this class is inheriting IClientValidatable interface which is from, so my viewmodel classlibrary housld have to depend on which I do not like.Ĭan I define this class in viewmodels class library without IClientValidatable interface. now I wanted to separate my viewmodel to separate class library. Till now this class is within my mvc project. ![]() asp.net-mvc-3 data-annotations or ask your own question. I know I can do this server side by overriding validation attribute like so. It has comparison logic in server and client side In my view I put a hidden field in for MaxValueForSize and I want to compare the entered value for Size to less than or equal to the MaxValueForSize property. ![]() I use it to decorate a property of my viewmodel to compare with another property in the same view model Below is my extension class for Custom Compare attribute as Data Annotation for comparing Numbers, date times
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |