我必须更新局部视图并获取json数据以更新下拉列表。如何在MVC5中通过jquery ajax调用更新部分视图并获取JSON数据?
最快的方法是让服务器端代码呈现部分视图并以字符串形式返回到ajax请求,然后获取ajax成功方法来替换html。
类似:
$.ajax({
type: "GET",
url: "your url of endpoint",
data: {your data},
success: function (response) {
$('your div to replace').empty().append(response);
},
error:function(){
//handle any errors
}
});