0

I have the following model in my ASP.NET application. I had a required validator on SubmitDate but have since removed it. However when I try to submit an entry into my DB via the web field, I still get a "SubmitDate is a required field".

namespace dev_apps.Models
{
    public class App
    {
        public int ID { get; set; }
        [DisplayFormat(DataFormatString = "{0:d}")]
        public DateTime SubmitDate { get; set; }
        public virtual string Entry { get; set; }

    }

    public class AppDBContext : DbContext
    {
        public DbSet<App> Apps { get; set; }
    }
}

Looking at the db (apps.sdf) the column properties for SubmitDate shows Allow Null = False. But I am unable to change this (its grayed out).

Any help is much appreciated.

Piotr Perak
  • 10,718
  • 9
  • 49
  • 86
thedeepfield
  • 6,138
  • 25
  • 72
  • 107

1 Answers1

1

You could try making the SubmitDate nullable.

public DateTime? SubmitDate { get; set; }

I'm assuming you are using Code First which would mean the db structure would change to reflect the model change.

scartag
  • 17,548
  • 3
  • 48
  • 52
  • @thedeepfield depends on the version .. if you are using mvc5 i guess it is. – scartag Oct 17 '14 at 22:15
  • @thedeepfield if you are not creating your db by hand then you are using code first .. which means EF creates the db structure based on your models – scartag Oct 17 '14 at 22:17
  • I'm using MVC3, and i did not create the db manually. I have since deleted apps.sdf and just ran the app again. Then I create 1 entry to get the db back. – thedeepfield Oct 17 '14 at 22:19
  • @thedeepfield you can delete the db, make changes to the model (like making the SubmitDate nullable as i've done in my answer) and when it creates the db again the column will be nullable. – scartag Oct 17 '14 at 22:33