Click here to Skip to main content
11,709,536 members (49,024 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: MVC3
Hi , I wanna to call and MVC post action with this definition
        public void Delete(Guid contactId)
            var contact = _contactRepository.GetContactById(contactId);

in a table with ajax call , this is my delete link
    <a href=""  önclick='DeleteFunction(@item.Id))'>Delete</a>

why this script doesn't work

<script type="text/javascript">
        type: "POST",
        url: @Url.Action("Delete","Contact"),
        data: data,
        success: success,
        dataType: dataType


please help me about that ,thanks
Posted 14-Jan-13 2:29am
Zoltán Zörgő at 14-Jan-13 8:34am
"Does not work" has no actual meaning.
Use fiddler or ie9 developer toolbar to check what url us actually called, what is passed, and what you get as result.
ahsan22 at 14-Jan-13 8:42am
actually I don't know how to do in ajax call , it should take any parameter based on my action ??
Zoltán Zörgő at 14-Jan-13 8:49am
Depend on your routing. But what I don't see is how the data is filled. Yous javascript snippet looks incomplete to me...
ahsan22 at 14-Jan-13 8:53am
that is it , it is incomplete and I don't know what to do , and didn't find any related sample on web.
ahsan22 at 15-Jan-13 17:35pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try something like this:
<script type="text/javascript">
function DeleteFunction(guid){
        type: "POST",
        url: @Url.Action("Delete","Contact"),
        data: JSON.stringify({contactId: guid}),
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        success: function (result) {
        async: true,
        processData: false
<a href="" onclick='DeleteFunction("@item.Id");'>Delete</a>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 525
1 OriginalGriff 250
2 Peter Leow 219
3 Maciej Los 185
4 Mika Wendelius 160
0 OriginalGriff 9,428
1 Sergey Alexandrovich Kryukov 9,037
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856

Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100