Saturday, 21 May 2016

MVC - Fix the following error - Error The name 'DateTimeFormatInfo' does not exist in the current context

Watch this on YouTube:
error while executing the following code:
public IEnumerable<SelectListItem> Months
        {
            get
            {
                return DateTimeFormatInfo
                       .InvariantInfo
                       .MonthNames
                       .Select((monthName, index) => new SelectListItem
                       {
                           Value = (index + 1).ToString(),
                           Text = monthName
                       });
            }
        }
To fix it - add the following using:
using System.Globalization;

No comments:

Post a Comment