0
我有以下几点看法(基本的 “编辑” 模板)值不能为空。参数名:实体
@model SuccessStories.Models.Testimonials
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Testimonials</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Id)
<div class="form-group">
@Html.LabelFor(model => model.Testimonial, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Testimonial, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Testimonial, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
而在我的控制下的ActionResult:
[HttpGet]
public ActionResult Edit(int id)
{
TestimonialsContext testContext = new TestimonialsContext();
Testimonials testimonials = testContext.testimonialContext.Find(id);
return View(testimonials);
}
[HttpPost]
public ActionResult Edit(Testimonials testimonial)
{
TestimonialsContext testContext = new TestimonialsContext();
testContext.Entry(testimonial).State = EntityState.Modified;
testContext.SaveChanges();
return RedirectToAction("Index");
}
的错误是在此行:
testContext.Entry(testimonial).State = EntityState.Modified;
我得到的错误是“值不能为空。 参数名称:实体
描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。
异常详细信息:System.ArgumentNullException:值不能为空。 参数名:。!。实体”
请帮我看这件事,但无法找到一个解决方案,将工作给我看
可能的是,你的'的TestContext。条目(推荐)''为'null'或'推荐'为'空' – Ian
我的数据库表只有一个id和证书类别。证词编辑正在文本输入中捕获。问题可能是它将id更改为null? –
'testimonial'为null。 – Rob