Bị lỗi db.SaveChanges()

Chào mọi người. Mình bị lỗi db.SaveChange() mấy ngày rồi nhưng chưa giải quyết được ạ. Mong được giúp đỡ


mình có 2 bảng có liên kết khóa ngoại (Khóa Ngoại IDChuDe).



bây giờ mình tạo Create cho bảng BanTin

mình dùng ViewBag để truyền dữ liệu cho Dropdowlist và dùng HttpPostedFileBase để lưu hình ảnh, CKEditor cho nhập liệu


Controller: Create

       [HttpGet]
        public ActionResult Create()
        {
            ViewBag.IDChuDe = new SelectList(db.ChuDe, "IDChuDe", "TenChuDe");
            return View();
        }

        //
        // POST: /Admin/TinTucAdmin/Create


        [HttpPost]
        [ValidateAntiForgeryToken]
        [ValidateInput(false)]
        public ActionResult Create(BanTin bantin, HttpPostedFileBase fileupload)
        {
            
            if(fileupload.ContentLength>0)
            {
                //lấy tên hình ảnh
                var fileName = Path.GetFileName(fileupload.FileName);
                
                //lấy hình ảnh chuyển vào thư mục hình ảnh
                var path = Path.Combine(Server.MapPath("~/ImageTinTuc"), fileName);
                if(System.IO.File.Exists(path))
                {
                    ViewBag.upload = "Hình ảnh tồn tại";
                    return View();
                }
                else
                {
                    //lưu hình ảnh vào thư mục
                    fileupload.SaveAs(path);
                    bantin.HinhDaiDien = fileName;
                }
            }
            db.BanTin.Add(bantin);
            
            db.SaveChanges();
            ViewBag.IDChuDe = new SelectList(db.ChuDe, "IDChuDe", "TenChuDe", bantin.IDChuDe);
            return RedirectToAction("Index");
        }

View

<body>
    @*thêm thuộc tính cho form để upload ảnh*@
    @using (Html.BeginForm("Create", "TinTucAdmin", FormMethod.Post, new { @enctype = "multipart/form-data" }))
    {
        @Html.AntiForgeryToken()
        @*@Html.ValidationSummary(true)*@
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="editor-label">
                @Html.LabelFor(model => model.IDChuDe,"IDChuDe")
            </div>
            <div class="editor-field">
                @Html.DropDownList("IDChuDe", null, new { @class = "form-control" })
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.HinhDaiDien)
            </div>
            <div class="editor-field">
                @*name của thẻ input phải trùng tên với tham số bên controller*@
                <input type="file" name="fileupload">
                @*thông báo trùng*@
                @ViewBag.upload
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.TieuDe)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.TieuDe)

            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.NoiDung)
            </div>
            <div class="editor-field">
                @Html.TextAreaFor(model => model.NoiDung, new { @id = "ckeContent" })

                @section scripts{
                    <script type="text/javascript">

                        CKEDITOR.replace('ckeContent');

                    </script>
                }

            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.GioiThieu)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.GioiThieu)

            </div>

            <p>
                <input type="submit" value="Lưu bài viết" /> @Html.ActionLink("Hủy", "Index")
            </p>
    }
</body>

giá trị truyền vào

bạn try catch cái exception validate như nó nói xem lỗi gì

Sao 1 cái IDChude allow null còn cái kia thì không ??

sửa lại bên View hả bạn

mình chưa rõ nên try catch chỗ nào

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?