使用Ajax仅更新部分视图 [英] Update Only Partial view using Ajax

查看:76
本文介绍了使用Ajax仅更新部分视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想使用Jquery Ajax更新下拉列表更改的部分视图。下拉是我的部分观点。这里我提到了使用的代码。但是观点没有变化。请提出宝贵的建议。



查看:



Hi all,

I want update a Partial view on dropdown change using Jquery Ajax. The dropdown is in my partial view. Here i have mentioned the code used. But there is no change in the view. Kindly give your valuable suggestion.

View :

@model MyModels.CustomerDetailsModel

@{
    var val = Json.Encode(Model);
}




<div id="myPartialViewDiv">
                       @{Html.RenderPartial("_PartialView", Model);
                       }
                   </div>





JS:





JS:

function ddlChange() {
      var check = @Html.Raw(val);
        $.ajax({
            async: false,
            url: '/Main/LoadddlView',
            data: '{model:' + JSON.stringify(check) + '}',
            type: 'post',
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            success: function (objOperations) {
                
               
                $("#myPartialViewDiv").html(objOperations);

            }
        });
}





控制器:





Controller :

[HttpPost]
        public ActionResult LoadddlView(DetailsModel model)
        {
        
               //Some Opeartion
               return PartialView("_DispositionView", model);
           
        }

推荐答案

.ajax({
async: false
url:' / Main / LoadddlView'
数据:' {model:' + JSON .stringify(check)+ ' }'
类型:< span class =code-string>' post'
dataType:' json'
contentType:' application / json; charset = utf-8'
成功: function (objOperations){
.ajax({ async: false, url: '/Main/LoadddlView', data: '{model:' + JSON.stringify(check) + '}', type: 'post', dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (objOperations) {


#myPartialViewDiv)HTML(objOperations)。

}
});
}
("#myPartialViewDiv").html(objOperations); } }); }





控制器:





Controller :

[HttpPost]
        public ActionResult LoadddlView(DetailsModel model)
        {
        
               //Some Opeartion
               return PartialView("_DispositionView", model);
           
        }


请尝试 dataType contentType 关于Ajax方法。 :)



Please try it without the dataType and contentType on Ajax method. :)

function ddlChange() {
      var check = @Html.Raw(val);


这篇关于使用Ajax仅更新部分视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆