Click here to Skip to main content
15,887,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I ,in MCV2.0 framework, created model with property of type DateTime.
I using maskedit also on that textbox for allowing only partial editing of date. But maskedit is submitting this form field with placeholders '_'
when user don't fill this entry.
Validation summary than have entry for that property like

The value '2010-10-__' is not valid for {...}.

How to localize that message? I certainly don't want it in English?
Any thoughts?
Posted

 
Share this answer
 
Comments
n.podbielski 6-Nov-10 4:02am    
Nope. This solution it's a pure ASP. My project is running on MVC2.0 framework.
But thanks Anyway! :)
E.F. Nijboer 7-Nov-10 9:17am    
I must have interpreted this "But maskedit is submitting this form field..." as being a web form.

You could however use COleDateTime::ParseDateTime to check the date. This will return true if the date is correct, false otherwise.
if (COleDateTime::ParseDateTime(MyDateMskEdit.ClipText)) {/* valid date */} else {/* invalid date */}

http://msdn.microsoft.com/en-US/library/37t16xc9%28v=VS.80%29.aspx
I added string value for date in model:

C#
[DatePickerValidator]
public string base_date{ get; set; }


for this date property.
String is always valid so this validation never occurs.
DatePickerValidator validates if this string is valid as date. If is not the controller adds appropriate message.

C#
public class DatePickerValidatorAttribute : ValidationAttribute
   {
       public override bool IsValid(object value)
       {
           var parsed_date = new DateTime();
           if (value != null && DateTime.TryParse(value.ToString(), out parsed_date)) return true;
           return false;
       }

       public override string FormatErrorMessage(string name)
       { return base.FormatErrorMessage(name); }
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900