本文介绍了如果您尝试删除应用程序数据库中的数据并且出现此错误,该怎么办。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 艾美
当我尝试删除应用程序数据库中的数据时,我收到此错误,当我单击删除按钮时,它显示参数字典包含非可空类型'系统的参数'id'的空条目。 Int32'
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'"
//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> }推荐答案
控制器在您的网址中需要 Id 参数但是你没有提供。 如: Controller is expecting an Id parameter in your URL but you aren't supplying that. Such as: localhost:56230/controller/DeleteF/1 //Here "1"(ID) is missing
您好伙计,请尝试在您的视图中插入以下代码: @using(Html.BeginForm( DeleteF,Admin,new {id = model.movieId})); Hi buddy, try inserting the following code in your view: @using (Html.BeginForm("DeleteF", "Admin", new {id = model.movieId}));
更多推荐
如果您尝试删除应用程序数据库中的数据并且出现此错误,该怎么办。
发布评论