Passing a DateTime to controller via URL causing error in ASP .NET MVC 3 (culture)

前端 未结 4 1663
轻奢々
轻奢々 2021-02-04 02:45

My application is setted with pt-BR culture (Date is dd-mm-yyyy) in web.config:



        
4条回答
  •  粉色の甜心
    2021-02-04 03:01

    As someone who does a lot of work with US companies, I've had a lot of experience with date issues.

    My best advice is to choose an unambiguous format when transmitting.

    dd-MMM-yyyy
    

    and

    yyyy-MM-dd
    

    Are safe bets, and will be successfully parsed by DateTime.Parse(obj).

    If changing the date format is not an option, you should look at DateTime.ParseExact, which allows you to specify the exact format string you are after.

提交回复
热议问题