1

I have a table that will use is populated by javascript when another table option is clicked. All of this works no problem, when I add the delete button to the table the onClick event fires but this isn't ever called in asp.net.

function DeleteLink(id) {
    $.ajax({
        url: '/PublicPages/LinkDelete/',
        data:{ id:id }
    });
}

please tell me where I've gone wrong.

I have tried

function DeleteLink(id) {
    $.ajax({
        url: '/PublicPages/LinkDelete/' + id
}

as well

UPDATE:

    [HttpPost]
    public async Task<IActionResult> LinkDelete(Guid id)
    {
        var pageId = _linkDataProvider.FindById(id).PublicPage.Id;
        _linkDataProvider.Delete(id);
        var page = await _pageDataProvider.FindById(pageId);
        var viewModel = _pageDataProvider.ConvertToViewModel(page);
        return View("Details", viewModel);
    }

UPDATE2

app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Flooring}/{action=Index}/{id?}"); });

4
  • 1
    If your DeleteLink action has HttpPost attribute you need to specify http method. Try to add type: "POST" in ajax setting. Commented Oct 30, 2016 at 15:45
  • please share the Action method also. Commented Oct 30, 2016 at 15:47
  • ` $.post({ url: '/PublicPages/LinkDelete/', data:{ id:id } });` this should work. Commented Oct 30, 2016 at 19:03
  • 1
    Please also share your routing setup. Commented Oct 30, 2016 at 21:23

1 Answer 1

2

You should specify http method in ajax settings. Try to change your javascript like below:

function DeleteLink(id) {
    $.ajax({
        type = 'POST',
        url: '/PublicPages/LinkDelete/' + id
    });
}

Update

If you prefer to use data:{ id:id } then you would need to create a model class:

public class DeleteModel
{
    public Guid Id{get;set;}
}

[HttpPost]
public async Task<IActionResult> LinkDelete([FromBody]DeleteModel model)
....
Sign up to request clarification or add additional context in comments.

1 Comment

this still is not firing LinkDelete

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.