如果您尝试删除应用程序数据库中的数据并且出现此错误,该怎么办。

编程入门 行业动态 更新时间:2024-10-27 18:31:10
本文介绍了如果您尝试删除应用程序数据库中的数据并且出现此错误,该怎么办。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我尝试删除应用程序数据库中的数据时,我收到此错误,当我单击删除按钮时,它显示参数字典包含非可空类型'系统的参数'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.movi​​eId})); Hi buddy, try inserting the following code in your view: @using (Html.BeginForm("DeleteF", "Admin", new {id = model.movieId}));

更多推荐

如果您尝试删除应用程序数据库中的数据并且出现此错误,该怎么办。

本文发布于:2023-11-06 09:36:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563329.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如果您   数据库中   应用程序   错误   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!