首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >参数类型“Edm.String”和“Edm.Int32”与此操作不兼容

参数类型“Edm.String”和“Edm.Int32”与此操作不兼容
EN

Stack Overflow用户
提问于 2016-08-08 15:16:46
回答 2查看 17.5K关注 0票数 6

我得到的错误类似于上面的标签,它将在

返回视图(st.employees.Find(Id));

上面只有一个地方,有人能帮我这个忙吗!我的代码是

代码语言:javascript
复制
     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");
    }

}

}

有人能帮我纠正这个错误吗?

EN

回答 2

Stack Overflow用户

发布于 2017-07-12 15:31:37

似乎您正在遵循MVC模式。

我也得到了这个错误,这是因为我将id参数作为整数传递,而不是我在模型中声明的"string“。

示例:

代码语言:javascript
复制
public class Object
{
    public string id { get; set; }
    public string property1{ get; set; }
    public string property2{ get; set; }
    public string property3{ get; set; }
}
票数 1
EN

Stack Overflow用户

发布于 2018-05-04 19:30:41

Find()将只接受数据类型类似于要使用Find()的表的主键的参数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38832906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档