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) {
</script><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