【发布时间】:2015-09-17 08:37:51
【问题描述】:
当我尝试在 ASP NET MVC 5 中编辑单个列时不断收到此错误
Cannot insert the value NULL into column 'naam', table
这是我的邮政编码
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index([Bind(Include = "id,email")] user user)
{
var username = HttpContext.User.Identity.Name;
if (ModelState.IsValid)
{
db.Entry(user).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(user);
}
这就是模型
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace LiemersApp.Models.EntityModels
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
public partial class profiel
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public profiel()
{
this.meldingens = new HashSet<meldingen>();
}
public int id { get; set; }
[DisplayName("Email:")]
public string email { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<meldingen> meldingens { get; set; }
}
}
所以我想知道为什么它不起作用,因为我只想将更改保存到电子邮件列任何想法为什么会发生这种情况,因为我无法弄清楚
问候
【问题讨论】:
-
错误很明显,您需要在名称列中插入值。
-
您展示的方法适用于
user类,但您展示的模型适用于profiel类!显示正确的代码。
标签: c# sql asp.net asp.net-mvc