Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I`m getting this error when i try to delete data in my application database, when i click on the delete button it says "The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32'"


C#
//This is my delete method in business logic
       public void DeleteMovie(MovieView model)
        {
            using (var movierepo = new MovieRepository())
            {
                Movie mov = movierepo.GetById(model.MovieId);
                movierepo.Delete(mov);
            }
        }        


    //My delete method inside the controller

        public ActionResult DeleteF(MovieView model, int id)
        {
                var m = movieLogic.GetById(id);
                movieLogic.DeleteMovie(m);

            return RedirectToAction("Index", "Admin");
        }
 
        [HttpGet]
        public ViewResult Update(int movieId)
        {
            var movie = movieLogic.GetById(movieId);
            return View(movie);
        }

        [HttpPost]
        public ActionResult Update(MovieView movie, HttpPostedFileBase image = null)
        {
            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    movie.MovieArt = image.ContentType;
                    movie.MovieArtData = new byte[image.ContentLength];
                    image.InputStream.Read(movie.MovieArtData, 0, image.ContentLength);
                }
                movieLogic.UpdateMovie(movie);
                TempData["message"] = string.Format("{0} has been saved", movie.Title);
                return RedirectToAction("Index");
            }
            else
            {
                // there is something wrong with the data values
                return View(movie);
            }
        }

    //This is part of my view

    @using (Html.BeginForm("DeleteF", "Admin"))
    {
        @Html.AntiForgeryToken()

        <div class="form-actions no-color">
            <input type="submit" value="Yes" class="btn btn-danger" />
            <span>
                @Html.ActionLink("No", "Index", null, new { @class = "btn btn-primary" })
            </span>
        </div>
    }
Posted
Updated 30-Jul-14 4:37am
v2
Comments
PIEBALDconsult 30-Jul-14 10:47am    
That depends on the application.

Controller is expecting an Id parameter in your URL but you aren't supplying that.
Such as:

http://localhost:56230/controller/DeleteF/1
//Here "1"(ID) is missing



--Amy
 
Share this answer
 
Hi buddy, try inserting the following code in your view:

@using (Html.BeginForm("DeleteF", "Admin", new {id = model.movieId}));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900