错误状态:'内部服务器错误'。错误代码:500 - jqGrid ASP.NET MVC [英] error Status: 'Internal Server Error'. Error Code: 500 - jqGrid ASP.NET MVC

查看:171
本文介绍了错误状态:'内部服务器错误'。错误代码:500 - jqGrid ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jqgrid模态窗体来添加和编辑表的行。我正在使用Entity框架和Database First方法从现有数据库创建模型。当我添加或编辑行时,行被正确地添加或编辑,并被正确地保存在数据库中,并且当我检索添加或编辑的行并且在jqGrid中查看时,它们被正确显示。但是,唯一的问题是当我添加或编辑,它会引发 错误状态:'内部服务器错误'。错误代码:500 在模态窗体中。任何人都知道为什么会发生这种情况?既然,添加或编辑正在发生,有没有办法忽略这个错误信息,使其不显示?



任何帮助是非常感谢!



编辑:

  public ActionResult创建(string oper,string id,Employee employee)
{
try
{
if(oper ==add)
{
if( ModelState.IsValid)
{
db.Employees.Add(employee);
db.SaveChanges();
return RedirectToAction(Index);
}
}
if(oper ==edit)
{
if(ModelState.IsValid)
{
db.Entry (employee).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction(Index);
}
}
if(oper ==del)
{
员工员工= db.Employees.Find(Int32.Parse(id));
db.Employees.Remove(employees);
db.SaveChanges();
return RedirectToAction(Index);
}
}
catch(InvalidOperationException ex)
{
}
catch(异常e)
{
}
}


解决方案

感谢大家所有的建议。我弄清楚我在做错什么实际上,问题不在于数据格式不正确或代码没有被打,问题是在我将更改保存到我的数据库之后,这就是为什么没有被捕获在异常块中。



将数据库中的更改保存为[db.SaveChanges()]后,我将重定向到索引操作。那就是问题所在。我正在重定向到错误的索引行动。此Index操作中的代码尝试返回一些为null的值,因此抛出ArgumentNullException并显示YSOD。



注意:我可以使用事件查看器发现ArgumentNullException。在运行中键入事件查看器和Goto Windows日志 - 应用程序。您将可以看到您的应用程序的所有警告。打开警告,转到常规选项卡,您将可以看到抛出什么样的异常。希望这有助于有需要的人。


I am using jqgrid Modal form to Add and Edit rows of the table. I am using Entity framework and Database First approach to create models from existing database. When I Add or Edit the rows, rows are added or edited correctly and being saved appropriately in the database and when I retrieve the added or edited rows and view in jqGrid, they are displayed correctly. But, the only issue is when I Add or Edit, it throws error Status: 'Internal Server Error'. Error Code: 500 in the modal form.

Anyone has any idea of why is this happening? Since, the add or edit is happening properly, is there a way that I can ignore this error message and make it not displayed at all?

Any help is greatly appreciated!

EDIT:

public ActionResult Create(string oper, string id, Employee employee)
{
try
{
 if (oper == "add")
 {
   if (ModelState.IsValid)
   {
    db.Employees.Add(employee);
    db.SaveChanges();
    return RedirectToAction("Index");   
   }
 }
 if (oper == "edit")
 {
  if (ModelState.IsValid)
  {
    db.Entry(employee).State = EntityState.Modified;
    db.SaveChanges();
    return RedirectToAction("Index");
  }
 }
  if (oper == "del") 
  {
    Employee employees = db.Employees.Find(Int32.Parse(id));
    db.Employees.Remove(employees);
    db.SaveChanges();
    return RedirectToAction("Index");
  }
}
catch (InvalidOperationException ex)
{
}
catch (Exception e)
{
}
}

解决方案

Thanks to everyone for all your suggestions. I figured out what I was doing wrong. Actually, the issue is not with incorrect data format or the code not being hit, the problem was after I saved changes to my database, that's why it was not caught in the exception block.

After saving the changes to the database as [db.SaveChanges()], I am redirecting to the Index Action. That's where the issue was. I was redirecting to the wrong Index action. The code inside this Index action tried to return some value that is null and hence ArgumentNullException was thrown and that displayed YSOD.

Note: I was able to spot the ArgumentNullException with Event Viewer. Type Event Viewer in Run and the Goto Windows Logs - Application. You will be able to see all the Warnings for your application. Open the warning, Goto General tab and you will be able to see what kind of exception is thrown. Hope this helps someone in need.

这篇关于错误状态:'内部服务器错误'。错误代码:500 - jqGrid ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆