I am calling Delete controller method from ajax on button click but when i click the button it gives error like "Object reference not set to an instance of an object."
I have write a code for the ajax and calling delete method previously the javascript code get called on every page load rather than on button click but then i add e.preventDefault(); The issue is now it is giving error rather then moving to the controller delete method.
My Javascript code
- <script> function DeleteCall(id) {
- [httppost]
- public ActionResult Delete(int? id) { if (id == null)
- { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } S
- tudent_Experience student_Experience = db.Student_Experience.Find(id);
- if (student_Experience == null) { return HttpNotFound(); }
-
- db.Student_Experience.Remove(student_Experience);
- db.SaveChanges(); return RedirectToAction("Create","Students");