error Status: 'Internal Server Error'. Error Code: 500 - jqGrid ASP.NET MVC

别来无恙 提交于 2019-12-12 02:08:56

问题


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)
{
}
}

回答1:


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.



来源:https://stackoverflow.com/questions/11743904/error-status-internal-server-error-error-code-500-jqgrid-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!