简体   繁体   中英

update partial view mvc3 with javascript

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.

Replace

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

with

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

要么

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM