MVC4 - '/'应用程序中的服务器错误

时间:2013-05-30 08:50:33

标签: entity-framework asp.net-mvc-4

我构建了一个简单的模型。 StartDate是DateTime2的原因是因为之前在我尝试使用DateTime时它给了我一个错误。

 public class Auction
{
    [Key]
    public string Id { get; set; }
    [Required]
    public string Title { get; set; }
    public string Description { get; set; }
    [Column(TypeName = "DateTime2")]
    [Display(Name = "StartTime")]
    public DateTime StartTime { get; set; }
    [Column(TypeName = "DateTime2")]

    public DateTime EndTime { get; set; }
    public int StartPrice { get; set; }
    public int CurrentPrice { get; set; }
    public string category { get; set; }

    public virtual Collection<Bid> Bids { get; private set; }

    public int BidCount
    {
        get { return Bids.Count; }
    }

    public Auction()
    {
        Bids = new Collection<Bid>();

    }

我在控制器中创建了一个create()函数。

     [HttpPost]
     public ActionResult create(Auction auction)
     {
         var categoryList = new SelectList(new[] { "auto", "elec", "games", "Home" });
         ViewBag.categoryList = categoryList;
         auction.StartTime= DateTime.Now;
         auction.EndTime = DateTime.Now.AddDays(7);

          if (ModelState.IsValid)
         {
             //Save the form
              var db = new AuctionsDataContext();
             db.Auctions.Add(auction);
             db.SaveChanges();

             return RedirectToAction("Index");

         }
         return View();

     }

当我尝试保存更改时出现此错误:

 Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

0 个答案:

没有答案