1

I have javascript function for update partial view. Now i need to update partial view that take one value and i cant do it :(

here is my function that works:

function clearData() {
    var urlclear = '@Url.Action("Clear", "Cart")';
    $.ajax({
        cache: false,
        type: 'POST',
        url: urlclear,
        success: function (data) {
            $('#AjaxUpdate').html(data);
        }
    });
}

and if i put:

function clearData(id) {
    var urlclear = '@Url.Action("Clear", "Cart", new {ID = id})';
    $.ajax({
        cache: false,
        type: 'POST',
        url: urlclear,
        success: function (data) {
            $('#AjaxUpdate').html(data);
        }
    });
}

it tells me that id is undefined.

Can someone please tell me what im doing wrong.

thx in advance.

2 Answers 2

2

Replace

var urlclear = '@Url.Action("Clear", "Cart", new {ID = id})';

with

var urlclear = "@Url.Action("Clear", "Cart")/"+id;
Sign up to request clarification or add additional context in comments.

Comments

1
var urlclear = '@Url.Action("Clear", "Cart")' + "?ID=" + id;

OR

var urlclear = '@Url.Action("Clear", "Cart")' + "/" + id;

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.