0
votes

This questions seems to have been answered before, but those answers don't work in my case as far as I know, since the codes in the previous questions were much different than my code.

I'm very new at MVC by the way.

This is the error I get:

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

Controller:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SimpleMVC.Models;

namespace SimpleMVC.Controllers
{
    public class AdminController : Controller
    {
        // GET: Admin
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult AddMovie(string Title, int Price)
        {
            using (MovieDb_Entities db = new MovieDb_Entities()){
                Movies item = new Movies();
                item.Title = Title;
                item.Price = Price;

                db.Movies.Add(item);
                db.SaveChanges();
            }
            return RedirectToAction("Index");
        }

        public ActionResult Hey()
        {
            return View();
        }
    }
}

Partial view:

<p>Add new movie</p>
<form method="post" action="/Admin/AddMovie">
    <input type="text" name="Title" placeholder="Title" /><br />
    <input type="text" name="Price" placeholder="Price" /><br />
    <input type="submit" value="Add Movie" />
</form>

Thank you in advance.

1
See 'EntityValidationErrors' property for more details. - did you do this? The first step is to follow the debugging instructions in the error message. - Ant P
Add the model please... - the validation is defined there - yossico
@AntP - I would if I knew where that property is, I don't know where to read it. - Mikkel
@yossico - How would I send you the model? As I said, I'm a huge MVC noob, but I'm trying to learn it - Mikkel
@Mikkel It's a property of the exception itself. I would advise debugging your application, stepping through to ensure all the values are set as you expect and then inspecting the exception when it is thrown. There are lots of resources floating around on debugging in Visual Studio. - Ant P

1 Answers

0
votes

Building the application fixed it. This is something I forgot to do.

Sorry.