c# - 您无法在 ASP.NET 中保存评论
问题描述
我有我上次从代码中删除的审查控制代码,public ActionResult Edit ([Bind (Exclude = "Name")]
我应该能够编辑和更改审查,不幸的是,我找不到问题。
[Authorize]
public class ReviewsController : BaseController
{
// GET: Reviews
public ActionResult Index([Bind (Prefix ="Id")]int productId)
{
var product = _db.Products.Find(productId);
if(product != null)
{
return View(product);
}
return HttpNotFound();
}
public ActionResult Create(int productId)
{
return View();
}
[HttpPost]
public ActionResult Create(Review model)
{
if(ModelState.IsValid)
{
model.Name = User.Identity.Name;
_db.Reviews.Add(model);
_db.SaveChanges();
return RedirectToAction("Index", new { id = model.ProductId });
}
return View(model);
}
public ActionResult Edit (int id)
{
var review = _db.Reviews.Find(id);
if (review.Name == User.Identity.Name)
{
if (review != null)
{
return View(review);
}
}
return RedirectToAction("Index", "Products");
}
[HttpPost]
public ActionResult Edit(Review model)
{
if (model.Name == User.Identity.Name)
{
if (ModelState.IsValid)
{
_db.Entry(model).State = System.Data.Entity.EntityState.Modified;
_db.SaveChanges();
return RedirectToAction("Index", new { id = model.ProductId });
}
}
return View(model);
}
}
以下是您要编辑和保存评论的地方
我需要做什么才能编辑评论并保存。
我应该在这段代码的哪里更改某些内容或其他地方可能有问题?
解决方案
推荐阅读
- java - 使用可折叠元素在网格中显示对象
- dc.js - dc.js 仅在 numberDisplay 中添加一些值
- java - 在java中循环遍历两个矩阵
- firebase - Firebase Crashlytics:dSYMS 未正确处理
- json - 如何将 aws-sdk-go 的输出设置为“文本”?
- javascript - 基于 JavaScript / jQuery 中的更多数据属性值隐藏/显示 div
- c# - 类型别名可以用来定义类型别名吗?
- r - 将向量替换为具有不同长度的上三角矩阵
- java - onActivityCreated 启动了 3 次
- java - Spring Boot 不起作用自定义 JPA 请求