I have my project using MVC and I’ve got my controller that instantiates a service, the service manages the repository and in the repository makes the CRUD operations. The problem is, once a I populate my grid control (Telerik) with the data from my service, if I make an update and I refresh the data, it appears the old data instead of the new one. I think it’s a problem of the persistance of my context variable that requires to be disposed/instantiated but not quite sure about when and where (the Unit Of Work variable is located at the service).
<HttpPost()>
<GridAction()>
Function Edit(id As Integer, name As String, clientNo As String, image As String, unit As String) As ActionResult
Try
Dim org = Me._orgService.GetOrgById(id)
With org
.orgNAME = name
.orgCLIENTNO = clientNo
.orgIMAGE = image
.orgUNIT = unit
End With
TryUpdateModel(org)
Me._orgService.EditOrg(org)
Catch ex As Exception
'Log the error
ModelState.AddModelError("", MS_UNABLE_SAVE_CHANGES)
Response.StatusCode = 500
Return Content(String.Join("", (From state In ModelState Select state).SelectMany(Function(s) s.Value.Errors).Select(Function(e) e.ErrorMessage).ToArray()))
End Try
Return View(New GridModel(All()))
End Function
This is the service
Public Sub EditOrg(org As hdmtORG) Implements IOrgService.EditOrg
Me._context.OrgRepository.Edit(org)
Save()
End Sub
This is the repository (generic)
Public Overridable Sub Update(entity As TEntity) Implements IEntityRepository(Of TEntity).Edit
Me._objectSet.Context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified)
End Sub
Any idea?
Thanks so much.
Try to use
<OutputCache(Duration:=0)> _