1

So I used this before, but this is a link, with that behaviour once the link is clicked

    Ajax.ActionLink("XXX", "UpdateGridView", new {  }, new AjaxOptions { UpdateTargetId = "configs"})
);

What I want is a function in JS doing the same, calling an Action and given a UpdateTargetId, it will re render that partial view with that Action.

Is it possible?

Thank you

EDIT:

 $.ajax({
            type: "POST",
            url: "AddUpdateConfigs",
            data: ({id: @Model.QueueMonitorConfigurationsID, pathType: $('#ddlConfigTypeName').val(), threshold:$('#ddlThreshold').val(), valueType:$('#ddlValueTypeName').val(), location: $('#txtbLocation').val(), limit: $('#txtbLimit').val(), config: $('#NewOrUpdate').val() }),
            dataType: 'application/json',
            statusCode: {
                404: function(){
                    alert("Data is duplicated");
                },
                405:function(){
                    alert("Location Path is not correct");
                },
                406: function(){
                    alert("Location Path has to be UNC path");
                },
                407: function(error){
                    alert(error);
                },
                410:function(result){
                    alert("Item added correctly");
                    $('#gridView').load('gvConfigurations');
                },
                411:function(result){
                    alert("Item updated correctly");
                }
            }
        });

So my code works, but when my Action returns with code 410, I want to call that Action and update the gridView gvConfigurations

4

1 回答 1

1

您可以使用以下$.ajax()功能:

$.ajax({
    url: '/SomeController/UpdateGridView',
    type: 'GET',
    success: function(result) {
        $('#configs').html(result);
    }
});

$.get()等价物:

$.get('/SomeController/UpdateGridView', function(result) {
    $('#configs').html(result);
});

或更短的等价物使用load()

$('#configs').load('/SomeController/UpdateGridView');

这 3 个 jQuery 片段都做同样的事情:它们发送一个 AJAX 请求到DOM 元素,并使用此 AJAX 调用返回的部分结果/SomeController/UpdateGridView更新 DOM 元素。id="configs"

于 2013-06-10T19:21:26.760 回答