Click here to Skip to main content
15,035,283 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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 :

JavaScript
@model MyModels.CustomerDetailsModel

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

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


JS:

JavaScript
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 :

C#
[HttpPost]
        public ActionResult LoadddlView(DetailsModel model)
        {
        
               //Some Opeartion
               return PartialView("_DispositionView", model);
           
        }
Posted
Updated 5-Jun-14 21:28pm
v3
Comments
Sampath Lokuge 6-Jun-14 4:04am
   
Did you check whether are there any js errors on the code using dev tools ?
John Sathish Tamilarasu 6-Jun-14 6:35am
   
No JS errors
Sampath Lokuge 6-Jun-14 6:36am
   
Have you tried the below solution ?

1 solution

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

function ddlChange() {
      var check = @Html.Raw(val);
        $.ajax({
            async: false,
            url: '/Main/LoadddlView',
            data: '{model:' + JSON.stringify(check) + '}',
            type: 'POST',
            success: function (objOperations) {
                
               
                $("#myPartialViewDiv").html(objOperations);
 
            }
        });
}
   
v2
Comments
John Sathish Tamilarasu 6-Jun-14 6:36am
   
Exact Solution.Thanks Sampath.
Sampath Lokuge 6-Jun-14 6:38am
   
You're warmly welcome. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900