我得到的错误类似于上面的标签,它将在
返回视图(st.employees.Find(Id));
上面只有一个地方,有人能帮我这个忙吗!我的代码是
namespace StartApp.Controllers
{
public class EmployController : Controller
{
StartEntities st = new StartEntities();
//List
public ActionResult List()
{
return View(st.employees.ToList());
}
//Details
public ActionResult Details(int id = 0)
{
return View(st.employees.Find(id));
}
//Create
public ActionResult Create()
{
return View();
}
[HttpPost,ValidateAntiForgeryToken]
public ActionResult Create(employee e)
{
using(st)
{
st.employees.Add(e);
try
{
st.SaveChanges();
}
catch
{
System.Diagnostics.Debug.WriteLine("Here is an error");
}
}
return RedirectToAction("List");
}
//edit
public ActionResult Edit(int id = 0)
{
return View(st.employees.Find(id));
}
[HttpPost,ValidateAntiForgeryToken]
public ActionResult Edit(employee e)
{
st.Entry(e).State = EntityState.Modified;
st.SaveChanges();
return RedirectToAction("List");
}
//Delete
public ActionResult Delete(int id = 0)
{
return View(st.employees.Find(id));
}
[HttpPost,ActionName("Delete")]
public ActionResult Delete_conf(int id)
{
employee emp = st.employees.Find(id);
st.employees.Remove(emp);
st.SaveChanges();
return RedirectToAction("List");
}
}}
有人能帮我纠正这个错误吗?
发布于 2017-07-12 15:31:37
似乎您正在遵循MVC模式。
我也得到了这个错误,这是因为我将id参数作为整数传递,而不是我在模型中声明的"string“。
示例:
public class Object
{
public string id { get; set; }
public string property1{ get; set; }
public string property2{ get; set; }
public string property3{ get; set; }
}发布于 2018-05-04 19:30:41
Find()将只接受数据类型类似于要使用Find()的表的主键的参数。
https://stackoverflow.com/questions/38832906
复制相似问题