Old CRM data displayed after page refresh

I am building a simple ASP.NET MVC web page that shows all active accounts from MS Dynamics CRM .

Basically, a page works well if I compile and run it (with F5). The problem appears when I go to the Microsoft Dynamics CRM web page, log in, and then change the status of one account from active to inactive. Now, when I refresh the page I create, I get the same old results.

I tried updating (F5), hard updating (Ctrl + F5), deleting the xrm object before returning the view, but nothing xrm . So I think I didn’t understand something.

Controllers /HomeControler.cs

 public ActionResult Index() { using (var xrm = new XrmServiceContext("Xrm")) { var accounts = from a in xrm.AccountSet where a.StateCode == 0 select a; List<AccountModel> accountModels = new List<AccountModel>(); foreach (var account in accounts) { Debug.WriteLine(c+"\t"+account.Id+"\t"+account.Name); Debug.WriteLine(account.Address1_Composite); accountModels.Add(new AccountModel( account.Id.ToString(), account.Name, account.Address1_Composite)); } ViewBag.Title = "Page Title"; ViewBag.AccountModels = accountModels; } return View(); } 

Views / Home / Index.cshtml

 @{ Layout = @"~/Views/Shared/_Layout.cshtml"; } <div class="table-responsive"> <table class="table table-bordered table-condensed table-hover"> <caption><h2>Active Accounts</h2></caption> <thead> <tr> <th>Account ID</th> <th>Account Name</th> <th>Account Address</th> </tr> </thead> <tbody> @{ foreach (var accountModel in ViewBag.AccountModels) { <tr> <td>@accountModel.Id</td> <td>@accountModel.Name</td> <td>@accountModel.Address</td> </tr> } } </tbody> </table> </div> 

EDIT: Now I noticed that only the update first after “Reconstruction and Launch” actually updates the site. Is this an IIS Express error (I am doing this locally)?

+5
source share
1 answer

It is important that you configure in web.config for the XRM context. By default, a service is created using the CachedOrganizationService , which, as its name implies, caches all data.

To disable caching, use the following configuration (replacing Xrm.XrmServiceContext, Xrm with your own ServiceContext):

 <microsoft.xrm.client> <contexts> <!-- Replace with your actual ServiceContext --> <add name="Xrm" type="Xrm.XrmServiceContext, Xrm" serviceName="Xrm" instanceMode="PerRequest"/> </contexts> <services> <!-- Disable cache --> <add name="Xrm" type="Microsoft.Xrm.Client.Services.OrganizationService, Microsoft.Xrm.Client"/> </services> </microsoft.xrm.client> 

For more information about the default configuration, check the Developer Extension Models Context Object Model on MSDN.

+2
source

All Articles