0

I'm trying to send the request to controller but the console returns 500 error. What is the problem here?

Thanks in advance!

JS CODE:

 $('.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(); }); }); }); 

Controller:

 //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"); } 

SCREENSHOT:

enter image description here

2 Answers 2

1

You are passing wrong paramert name.

Change your parameter name from param to id in 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(); }); }); 

And your button must have data-id attribute. like this

<input type="button" class="delete_btn" value="Test" data-id="7" /> 
Sign up to request clarification or add additional context in comments.

2 Comments

can show screenshot of your console error or network tab. and How you are getting id value.
It is up there.
0

You are performing delete operation so you need to make post or delete request and in controller you need to decorate action method by [httpPost].

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.