开发者

Saving a DateTime value isn't working in production MVC3 server

开发者 https://www.devze.com 2023-04-04 11:42 出处:网络
This works in my dev machine, but not on my actual production server. I\'m just trying to register a user, but the date of birth has to be formatted dd/mm/yyyy. For example: 28/09/1980.

This works in my dev machine, but not on my actual production server.

I'm just trying to register a user, but the date of birth has to be formatted dd/mm/yyyy. For example: 28/09/1980.

This works very well on my dev machine, I can register and it's saving the date of birth correctly.

But when running the exact same code on the product server I get the error:

The value '29/08/1980' is not valid for Fecha de Nacimiento (dd-mm-aaaa):.

What should I be looking for and what could be causing the date to be saved correctl on my dev machine, but refuse to work well on production?

If I switch the values to 09/28/1989 it works fine, but due to way dates are formatted here in Bolivia, I need to use Day then Month, then Year.

Here's the [HttpPost] Action method that runs when the user clicks the submit button:

[HttpPost]
public ActionResult Register(UserModel model)
{
    EFCityRepository cityRepo = new EFCityRepository();
    model.Cities = new List<SelectListItem>();
    foreach (var city in cityRepo.FindAllCities())
    {
        model.Cities.Add(new SelectListItem { Text = city.Name, Value = city.CityId.ToString(), Selected = true });
    }

    EFGenderRepository genderRepo = new EFGenderRepository();
    model.Genders = new List<SelectListItem>();
    foreach (var gender in genderRepo.FindAllGenders())
    {
        model.Genders.Add(new SelectListItem { Text = gender.Name, Value = gender.GenderId.ToString(), Selected = true });
    }

    if (ModelState.IsValid)
    {
        Domain.User user = Mapper.Map<UserModel, Site.Domain.User>(model);
        user.UserRoleId = 1;
        user.EmailVerificationCode = SecurityHelpers.GenerateRandomToken();
        user.IsActive = true;
        user.LancesSpent = 0;
        user.GoldShopPointsSpent = 0;
        user.LanceCreditBalance = 25;
        user.GoldShopCreditBalance = 0;
        user.DateOfRegistry = DateTime.Now;
        user.LastDateLogin = DateTime.Now;

        var result = userRepo.CreateUser(user);

        if (result == UserCreationResults.Ok)
        {
            SecurityHelpers.SendVerificationEmail(user.Email, user.UserId, user.EmailVerificationCode);
            FormsAuthentication.SetAuthCookie(model.Login, false /* createPersistentCookie */);
            return RedirectToAction("Index", "Home");
        }
        else
        {
            switch (result)
            {
                case UserCreationResults.UsernameExists:
                    ModelState.AddMode开发者_如何学JAVAlError("", "El nombre de usuario ya esta siendo utilizado.");
                    break;
                case UserCreationResults.EmailAlreadyExists:
                    ModelState.AddModelError("", "Ese correo ya esta en uso.");
                    break;
                case UserCreationResults.NicknameAlreadyExists:
                    ModelState.AddModelError("", "El nickname ya esta siendo utilizado.");
                    break;
                case UserCreationResults.UnknownError:
                    ModelState.AddModelError("", "Algo durante el registro. Por favor intente de nuevo.");
                    break;
                default:
                    break;
            }
        }
    }

    // If we got this far, something failed, redisplay form
    return View(model);
}

}


Set the culture in your web.config:

<globalization culture="es-BO" uiCulture="es-BO" />
0

精彩评论

暂无评论...
验证码 换一张
取 消