0

I have created a windows form based application and am using the simple membership AccountModel. On the registration form I am having problems with the date format when the application is uploaded to azure.

Locally I am able to enter the format "31/10/2013" but on the azure hosted application I must enter it in the format "10/31/2013". How can I override the validation so that it allows the use of DD/MM/YYYY format

My register model is as follows:

public class RegisterModel
{
    [Required]
    [Display(Name = "Username")]
    public string UserName { get; set; }

    [Required]
    [Display(Name = "Forename")]
    public string Forename { get; set; }

    [Required]
    [Display(Name = "Surname")]
    public string Surname { get; set; }

    [Required]
    [Display(Name = "DOB")]
    [DataType(DataType.Date)]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd.MM.yyyy}")]
    public DateTime DOB { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Confirm password")]
    [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
    public string ConfirmPassword { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "Secret Answer")]
    public string SecretAnswer { get; set; }
}

I tried applying a dateformat to the DOB property as above but on azure it is still validating against MM/DD/YYYY

4

1 に答える 1

3

Mvc コントロール ツールキットの FormatAttribute を使用すると、開発者は、次の例に示すように、クライアント側でプロパティの表現に使用する形式を定義できます。

    Format(Prefix="Date of birth is: ", ClientFormat = "d", NullDisplayText="No date of birth available")]
    public DateTime? BirthDate { get; set; }

このようにして、ここで説明されているように、文字列をグローバル化できます。

Below the list of all supported date format:
Format  Meaning     "en-US"
f   Long Date, Short Time   dddd, MMMM dd, yyyy h:mm tt
F   Long Date, Long Time    dddd, MMMM dd, yyyy h:mm:ss tt
G   Short Date, Long Time   M/d/yyyy h:mm:ss tt
t   Short Time  h:mm tt
T   Long Time   h:mm:ss tt
d   Short Date  M/d/yyyy
D   Long Date   dddd, MMMM dd, yyyy
Y   Month/Year  MMMM, yyyy
M   Month/Day   yyyy MMMM
于 2013-10-16T10:11:53.933 に答える