This is a migrated thread and some comments may be shown as answers.

[Solved] model window showing old contents after partial view refresh post ajax call

2 Answers 112 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Narayanarao
Top achievements
Rank 1
Narayanarao asked on 02 Jan 2012, 06:37 AM
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);
      }


2 Answers, 1 is accepted

Sort by
0
Narayanarao
Top achievements
Rank 1
answered on 02 Jan 2012, 10:13 AM
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();
        
 
             
           }    
       });
 
         
          
 
       }
0
Petur Subev
Telerik team
answered on 03 Jan 2012, 11:00 AM
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
Tags
Window
Asked by
Narayanarao
Top achievements
Rank 1
Answers by
Narayanarao
Top achievements
Rank 1
Petur Subev
Telerik team
Share this question
or