0

I want to delete my record from database using jquery. when I save my file I use the following code,

The record Id's there..

Jobs

Controller Code

public ActionResult Delete(int id)
    {
        Job job = _repository.GetJob(id);
        if (job != null)
        {
            _repository.DeleteJobLanguages(id);
            _repository.DeleteJobLocations(id);
            _repository.DeleteJobPreferredIndustries(id);
            _repository.DeleteJobRequiredQualifications(id);
            _repository.DeleteJobRoles(id);
            _repository.DeleteJobskills(id);
            _repository.DeleteJob(id);
        }

        return View(job);

    }

Jquery Dial4Jobz.Job.Add = function (sender) { var form = $(sender).parent(); var data = form.serialize();

var url = form.attr('action');
$.ajax({
    type: "POST",
    url: url,
    data: data,
    dataType: "json",
    success: function (response) {
        Dial4Jobz.Common.ShowMessageBar(response.Message);
    },
    error: function (xhr, status, error) {
        Dial4Jobz.Common.ShowMessageBar(xhr.statusText);
    }
});
return false;

};

Here when I click submit button, it calls the jquery. Then it shows some error. How to write code in jquery for delete?

4
  • 1
    Delete record from where, exactly? Commented Jun 10, 2013 at 7:25
  • 1
    All in all, you'll need to write server-side procedure, that takes some unique ID of your record and deletes it from wherever it is. Commented Jun 10, 2013 at 7:28
  • 1
    It really depends on the implementation of your server side... Commented Jun 10, 2013 at 7:29
  • i updated my question.Please take a view Commented Jun 10, 2013 at 7:32

1 Answer 1

2

You could have a server side controller action which will take the id of the record that needs to be deleted:

[HttpDelete]
public ActionResult Delete(int id)
{
    repository.Delete(id);
    return Json(new { id = id });
}

and then the same way you could use AJAX to invoke it:

$.ajax({
    type: "DELETE",
    url: url,
    data: { id: '123' }, // <-- put the id of the record you want to delete here
    success: function (response) {

    },
    error: function (xhr, status, error) {
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.