我想更新我的表中的特定行,但我得到一個異常的類型「System.Data.Entity.Infrastructure.DbUpdateConcurrencyException」發生在EntityFramework.dll但在用戶代碼中沒有處理我越來越'System.Data.Entity.Infrastructure.DbUpdateConcurrencyException'.....當我試圖更新我的表中的一行
{「商店更新,插入或刪除語句影響的行的意外數字(0)。實體可以有「
我的操作方法是
已被修改或刪除,因爲實體已被加載,請參閱 http://go.microsoft.com/fwlink/?LinkId=472540瞭解和處理樂觀併發異常。public ActionResult createedit()
{
int id = Convert.ToInt32(Session["UserID"]);
var Certtt = (from cert in db.TBL_UserRegistration where cert.UserLoginID == id select cert).FirstOrDefault();
TBL_UserRegistration u = db.TBL_UserRegistration.Find(Certtt.UserRegistrationID);
return View(u);
}
[HttpPost]
public ActionResult createedit(TBL_UserRegistration user, HttpPostedFileBase imageup)
{
if(imageup != null)
{
user.UserImage = new byte[imageup.ContentLength];
imageup.InputStream.Read(user.UserImage, 0, imageup.ContentLength);
}
db.Entry(user).State = EntityState.Modified;
db.SaveChanges();
return View(user);
}
我看來
@using (Html.BeginForm("createedit", "UserRegistration", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<form class="wiwet-checkout">
<div class="row">
<div class="col-sm-6">
<!-- <input type="text" placeholder="First Name" />-->
@*@Html.LabelFor(model => model.UserFirstName, htmlAttributes: new { @class = "text-label", @placeholder = "Password" })*@
@Html.EditorFor(model => model.UserFirstName, new { htmlAttributes = new { @class = "form-control", @placeholder = "First Name" } })
@Html.ValidationMessageFor(model => model.UserFirstName, "")
</div>
.
.
.
}
我的模型TBL_UserResgistration是
public partial class TBL_UserRegistration
{
public TBL_UserRegistration()
{
this.TBL_Payment = new HashSet<TBL_Payment>();
}
public int UserRegistrationID { get; set; }
public Nullable<System.DateTime> UserRegistrationDate { get; set; }
public string Username { get; set; }
public string UserPassword { get; set; }
public string UserFirstName { get; set; }
public string UserLastName { get; set; }
public string UserEmail { get; set; }
public string UserType { get; set; }
public string UserCity { get; set; }
public string UserState { get; set; }
public string UserCountry { get; set; }
public Nullable<int> UserZip { get; set; }
public string UserAddressLine1 { get; set; }
public string UserAdressLine2 { get; set; }
public Nullable<long> UserPhone1 { get; set; }
public Nullable<long> UserPhone2 { get; set; }
public byte[] UserImage { get; set; }
public Nullable<int> UserLoginID { get; set; }
public virtual TBL_Login TBL_Login { get; set; }
public virtual ICollection<TBL_Payment> TBL_Payment { get; set; }
}
可以添加您的TBL_UserRegistration模型隱藏
? – Munzer
是的只是片刻 – PRADEEP
@Munzer先生請看看我剛纔編輯的帖子 – PRADEEP