MVC Error 500 – Server Encountered an Internal Issue

I'm having an issue sending a request to the controller, and I keep receiving a 500 error in the console. Can someone help me identify what could be going wrong here?

Thank you in advance!

Here is the JavaScript code I am working with:

    $('.delete_btn').on('click', function () {
        $.get("/List/Delete", { param: $(this).data('id') }, function (data) {
            $('#modal_window').replaceWith('<div id="modal_window">' + data + '</div>');
            $('#modal_window').show();
        });
    });
});

This is the controller code that is causing the problem:

  //DELETE ITEM
    public ActionResult Delete(int id)
    {
        H_Table item = db_connection.H_Table.Find(id);
        db_connection.H_Table.Remove(item);
        db_connection.SaveChanges();
        return RedirectToAction("Index");
    }

Here is a screenshot for reference:

https://i.sstatic.net/zj1be.png

Answer №1

You have made a mistake with the parameter name.

To fix this issue, update your parameter name from param to id in your ajax request.

$('.delete_btn').on('click', function () {
           $.get("/List/Delete", { id: $(this).data('id') }, function (data) {
               $('#modal_window').replaceWith('<div id="modal_window">' + data + '</div>');
               $('#modal_window').show();
           });
       });

Also, make sure that your button includes the data-id attribute like this:

<input type="button" class="delete_btn" value="Test" data-id="7" />

Answer №2

When conducting a delete operation, ensure you are sending either a post or delete request. In the controller, remember to annotate the action method with [httpPost].

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The top scrolling behavior on click applies exclusively to the first set of Bootstrap 5 tabs

I am experiencing an issue with my HTML webpage that contains multiple BS5 Nav Tabs. The first tab is not functioning properly, while all the other tabs are working smoothly. When I click on the first BS5 Nav Tab, the page scrolls to the top with the addre ...

Is there a way to include the request body (req.body) in the msg object using express-winston?

My current challenge involves logging {{ req.body }} using the msg: object in express-winston. Even after whitelisting the body with expressWinston.requestWhitelist.push('body');, it still does not appear in the log. export const accessLogger = ...

What is the process for determining the directory in which CKEditor looks for configuration and language files?

When CKEditor is loaded on a page, it searches for its configuration files relative to the location where it was initially loaded from, rather than the location of ckeditor.js. For example, loading CKEditor on the page http://www.example.com/articles/1 wou ...

What is the process for consumers to provide constructor parameters in Angular 2?

Is it possible to modify the field of a component instance? Let's consider an example in test.component.ts: @Component({ selector: 'test', }) export class TestComponent { @Input() temp; temp2; constructor(arg) { ...

Calculate the previous date excluding Sundays by subtracting the specified number of days from the given date

I'm experiencing an issue with this Date : 09/30/2014 NumOfDays : 5 Expected PreComputed Date : 09/24/2014 ---------------------------- 09/29/2014 Day 1 09/28/2014(Sunday) Skip 09/27/2014 Day 2 09/26/2014 Day 3 09 ...

Guide on making a JavaScript button with both "light and dark" modes

Currently, I am attempting to change the color scheme of the page by adjusting the :root variables using a function called changeBackgrondColor(). This function is then assigned to the fontAwesome moon "button". However, when I click on the moon, the pag ...

Replacement for Formspree in React applications or static websites

Currently in the process of creating a new portfolio website and I am looking to include a contact form. The website is being developed using React, and my initial plan was to use Formspree to integrate a contact form without the need for a backend. Unfort ...

Error encountered due to CSRF token mismatch while attempting to disable data processing and set content type as false

Hey everyone, I am currently working on sending files to a Laravel server using ajax. To achieve this, I need to create form data and send it with the ajax request. In order to prevent illegal invocation, I have set the following: processData: false, con ...

When capturing photos using h5 on iOS devices, the browser may experience a flash back issue

I have been searching Baidu and Google for a while now, but I still haven't found a solution. Here is the specific issue: When using h5 to take photos on iOS systems, the browser flashes back. HTML Code <img src="xxx" onclick="sta ...

Switch polygon setting during event on Vue Google Map

Looking for a way to change the stroke color of a polygon when hovering over it. Struggling to locate proper documentation on how to access the setOptions method from events. <GmapMap ref="google_map" :center="{ lat: 0, lng: -0 }"> ...

Exploring the Depths of Google Chrome: Unleashing the Power of

While a similar question has been posed previously, I am encountering difficulties debugging Javascript in Google Chrome. When I navigate to Page > Developer, the "Debug Javascript" function (Ctrl+Shift+L) is not active. Even trying Alt + ` does not se ...

Tips for retrieving data from a database with just one key press

There is a text field that triggers a JavaScript function when a key is pressed. <input type="text" class="text" id="txt_sh_vid" onKeyPress="vhc_record()" maxlength="4"> The function takes the input from the text field and searches for a result in t ...

Display geographic data using d3 with geoJSON

I am struggling to render a geoJSON file using d3 because I am having trouble targeting the correct features for projection. Instead of working with the typical us.json file used in many d3 examples, my current map focuses on United States "Commuting Zone ...

What possible reasons could there be for my vue project failing to load the JavaScript file?

I encountered an issue with my login page and script.js file while setting up my project. Strangely, my Vue application is not loading the JavaScript file as expected. The console displays this error message: https://i.sstatic.net/QG0hL.png The error seem ...

How to display a PDF file stored in the documents directory of an iOS device with Phonegap

I'm encountering an issue when it comes to displaying a PDF using HTML, PhoneGap, or JavaScript. The web application I'm working on is developed in Sencha Touch 2. Here's exactly what I need: I need to display a PDF file located in the d ...

Tips for extracting the values of multiple input fields in JavaScript and displaying them on a webpage

I want to collect all the values from input fields and display them on the website. Check out my code snippet below: var button = document.querySelector("button"); button.addEventListener("click", function() { var inputs = document.querySelectorAll( ...

Guide to automatically loading a default child route in Angular 1.5 using ui-router

Hello, I am looking to set a default child route to load as soon as the page loads. Below is the code snippet: $stateProvider.state('userlist', { url: '/users', component: 'users', data:{"name":"abhi"}, resolv ...

Submitting a form is disabled when there are multiple React form inputs

I have a simple code example that is working correctly as expected. You can check it out here: https://jsfiddle.net/x1suxu9h/ var Hello = React.createClass({ getInitialState: function() { return { msg: '' } }, onSubmit: function(e) { ...

Exploring the capabilities of Google Apps Script for looping and generating output

I have two spreadsheets named rawData and processedData. The content of rawData is as follows: Status Title Options Live Title1 Option1, Option2, Option3, Option4 Live Title2 Option1, Option2, Option3, Option4, Option5 Live Title3 Option1, O ...

Create a visual representation using a push button

Hey there, I'm attempting to create an image using a button on canvas. However, I'm facing an issue where I can't draw on the clear canvas. Here's my code: <!doctype html> <html> <head> <meta charset="utf-8"> ...