我有 2 个问题,1. 我有一个编辑操作并使用 formcollection 从 Httppost 上的HiddenFor中获取值,然后我用它来更改另一个数据库表,我想知道有没有一种方法可以提交表单后查看该 FormCollection 的值?
[HttpPost]
public ActionResult Edit(relisting house,FormCollection tt)
{
if (ModelState.IsValid)
{
// I would like a way to check the value of getid after submission since
//my code isn't working. This is an EDIT Action so the GETID has a value
//atleast before the post.
int getid = Convert.ToInt32(tt["RegistrationID"]);
var checksopen = (from d in db.openhouses where getid == d.RegistrationID
select d).FirstOrDefault();
house.squarefeet = checksopen.squarefeet;
house.city = checksopen.city;
db.Entry(checksopen).State = EntityState.Modified;
db.SaveChanges();
}
return View(house);
}
我的最后一个问题是我上面的完整代码使用 2 db.Entry().State = EntityState.Modified; 但只有 1 个在工作;有什么可以使第二个 entity.modified 不起作用?假设checkopen确实有匹配项?我正在将数据从重新列出的父模型传递到子模型openhouse,因此对于每个 openhouse 都有一个重新列出,所以我想捕获两者的变化以保持同步。
[HttpPost]
public ActionResult Edit(relisting house,FormCollection tt)
{
if (ModelState.IsValid)
{
// This one works
db.Entry(house).State = EntityState.Modified;
db.SaveChanges();
// This one doesn't work
int getid = Convert.ToInt32(Request.Form["RegistrationID"]);
var checksopen = (from d in db.openhouses where getid ==
d.RegistrationID select d).FirstOrDefault();
house.squarefeet = checksopen.squarefeet;
house.city = checksopen.city;
db.Entry(checksopen).State = EntityState.Modified;
db.SaveChanges();
}
return View(house);
}