Articles → ASP .NET MVC → Internal server error (500) in MVC

Internal server error (500) in MVC

Create a MVC project and database table

Picture showing the design view of the sample table

Click to Enlarge

Create a button on index

    ViewBag.Title = "Home Page";

<script src="" type="text/javascript"></script>
<script type="text/javascript">
               function () {
                       function () {
                               type: "POST",
                               url: "@Url.Action("Insert", "Home")",
                               success: function (data) {
                               error: function (err) {
<a href="#" id="lnkClick">Click</a>

public ActionResult Insert() {
  using(SqlConnection connection = new SqlConnection(“conn string”)) {
    using(SqlCommand command = new SqlCommand("Insert into Employee(Employee_name) values('Employee 1')", connection)) {
  return View();

Picture showing the error message when the application is deployed on the server

Click to Enlarge

Global.asax comes for rescue

protected void Application_EndRequest() {
  Exception[] ex = this.Context.AllErrors;
  if (ex != null)
    System.IO.File.WriteAllText(@ "c:\test\exception.txt", ex[0].Message);

Picture showing the actual error in the text file for the internal server error 500

Click to Enlarge

Posted By  -  Karan Gupta
Posted On  -  Sunday, December 6, 2015


Your Email Id  
Query/FeedbackCharacters remaining 250