Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > Window > model window showing old contents after partial view refresh post ajax call

Not answered model window showing old contents after partial view refresh post ajax call

Feed from this thread
  • Narayanarao avatar

    Posted on Jan 2, 2012 (permalink)

    Hi Telerik team,

    I have a model window in my partial view, I make an ajax call to update some values and read the same again in model window. 

    my problem is after the window is opened , the new value does not appear.

    i have debug using break points and see that the partial view having model  window form fields are created with new value, but during rendering still do not get updated form values.

    attached is the code. Also i tried using the cache: flase to make sure it is refreshed but does not help.. I have tried multiple things to make sure it works but in vain

    @(
    Html.Telerik().Window()
            .Name("EditContactWindow")
            .Title("Edit Contact")
            .Content(@<text>
            @{ Html.EnableClientValidation();
               Html.ValidationSummary(true);
                 
             }
              
             <script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/MicrosoftMvcValidation.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>     
     
        @using (Html.BeginForm("GetProfile", "PeopleManagement", FormMethod.Post, new { id = "EditContactForm" }))
        {
            <p class="note">
                Please Enter the contact details below</p>
             
       
            <table border="0" cellpadding="0" cellspacing="0" id="EditContactsTable">
             
                @{                
                    string toCheck = ViewBag.ContactIDToEdit;
                    int count = (from n in Model.PartnerDetails.Contacts where n.PrimaryContactId==toCheck select n).Count();
                        //Model.PartnerDetails.Contacts.Count(listItem => (listItem.PrimaryContactId.Equals(toCheck)));
                 }
             
                <tr>
                    <td class="table_label_cell" width="20%" >
                        <font color="red">*</font><label for="firstname">@ViewResources.PartnerManagement.GetPartnerProfile.FirstName :</label>
                    </td>
                    <td class="table_value_cell" width="40%">                   
                        @Html.TextBoxFor(m => m.PartnerDetails.Contacts[count].PrimaryContacts.FirstName)
                         
                    </td>
                    <td class="table_value_cell" width="40%">
                        @Html.ValidationMessageFor(e => e.PartnerDetails.Contacts[count].PrimaryContacts.FirstName)
                    </td>
                </tr>
                <tr>
                    <td class="table_label_cell" width="20%">
                        <font color="red">*</font><label for="lastname">@ViewResources.PartnerManagement.GetPartnerProfile.LastName :</label>
                    </td>
                    <td class="table_value_cell" width="40%">
                         @Html.TextBoxFor(m => m.PartnerDetails.Contacts[count].PrimaryContacts.LastName)
                    </td>
                    <td class="table_value_cell" width="40%">
                        @Html.ValidationMessageFor(e => e.PartnerDetails.Contacts[count].PrimaryContacts.LastName)
                    </td>
                </tr>
                 
                <tr>
                    <td colspan="2">
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="3">
                        <button type="submit" class="t-button t-state-default" style="width: 100px">@Save</button>
                         
                        <input type="reset" title="Close" value="Close" class="t-button t-state-default" style="width: 100px" onclick="closeNewContactWindow()" />
                    </td>
                </tr>
            </table>
            <br />
                     
        }
        </text>)
            .Width(700)
            .Height(320)
            .Draggable(true)
            .Modal(true)
            .Visible(false)
            .ClientEvents(t => t.OnLoad("ModelWindow_onLoad"))

    The Window is involed after ajax call using below script

    function setHiddenFieldValue(buttonEditClicked)
      {
       
       
     
      $('#contactIdHiddenFld').val("");
       
      $('#contactIdHiddenFld').val(buttonEditClicked.title) ;
      alert($('#contactIdHiddenFld').val());
     
       
      $.ajax({        
          url: "@Url.Action("SetProfileContactID", "PeopleManagement")",        
          data: {partnerContactID: $("#contactIdHiddenFld").val()},        
          dataType: 'html',        
          type: "POST",        
          error: function() {            
              alert("An error occurred.");        
          },        
          success: function(data) {            
            var windowElement = $('#EditContactWindow');        
        windowElement.data('tWindow').center().open();
                     
             
          }    
      });
     
        
         
     
      }

    Also below is the code from controller that refreshes partial view.

    [HttpPost]
          public ActionResult SetProfileContactID(string partnerContactID)
          {
              ViewBag.ContactIDToEdit = partnerContactID;
     
           
              //Forming the partner details model for GetPartnerProfile view
              DetailsModel Details = new Details();// logic to fill up this
     
              DetailsViewModel DetailsViewModel = new DetailsViewModel();
              DetailsViewModel.Details = Details;
               
     
              return PartialView("GetContactsPartial", DetailsViewModel);
          }


    Reply

  • Narayanarao avatar

    Posted on Jan 2, 2012 (permalink)

    i also updated teh script to update the result in div containing the model window partial view

    function setHiddenFieldValue(buttonEditClicked)
           {
            
            
     
           $('#contactIdHiddenFld').val("");
            
           $('#contactIdHiddenFld').val(buttonEditClicked.title) ;
           alert($('#contactIdHiddenFld').val());
         
            
           $.ajax({        
               url: "PartnerManagement/SetPartnerProfileContactID",        
               data: {partnerContactID: $("#contactIdHiddenFld").val()},        
               dataType: 'html',
               cache: false,       
               type: "GET",        
               error: function() {            
                   alert("An error occurred.");        
               },        
               success: function(result) {            
               debugger;
     
            
           $('#EditContactDiv').html(result);
                
                
                 var windowElement = $('#EditContactWindow');        
             windowElement.data('tWindow').center().open();
            
           jQuery.validator.unobtrusive.parse('EditContactForm');
           Sys.Mvc.FormContext._Application_Load();
            
     
                 
               }    
           });
     
             
              
     
           }

    Reply

  • Petur Subev Petur Subev admin's avatar

    Posted on Jan 3, 2012 (permalink)

    Hello Narayanarao,


    To properly set the value of the window you need to use the client method of the window called content().
    i.e.
    $('#EditContactWindow').data('tWindow').content(result);


    Kind regards,
    Petur Subev
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > Window > model window showing old contents after partial view refresh post ajax call
Related resources for "model window showing old contents after partial view refresh post ajax call"

ASP.NET MVC Window Features  |  Documentation  |  Demos  |  Telerik TV ]