Bind Exclude Asp.net MVC not working with LINQ Entity

I need to work on ASP.NET MVC for a while. I am doing a tutorial Create a movie database in ASP.NET MVC that still uses the ADO.NET Enity Model. I managed to create a list view from the LINQ Entity Model. So here is my problem. The Bind attribute does not work on my SQL entity.

Original code with Ado.NET

        public ActionResult Create([Bind(Exclude="Id")] Movie movieToCreate)

        {
             if (!ModelState.IsValid)
                return View(); 

            _db.AddToMovieSet(movieToCreate);
            _db.SaveChanges(); 
            return RedirectToAction("Index");
        } 

My LINQ Code

    public ActionResult Create([Bind(Exclude = "Id")] Movies movieToCreate)
    {
        if (!ModelState.IsValid)
        {
            return View();
        }
        _db_linq.Movies.InsertOnSubmit(movieToCreate);
        _db_linq.SubmitChanges();

        return RedirectToAction("Index");
    }

But the Id field is not excluded. Any ideas? Thanks!

+3
source share
1 answer

ID, , int . - , , . , .

, , IDI IsIdentity true LINQ.

+7

Source: https://habr.com/ru/post/1709275/


All Articles