我的项目使用MVC,我有我的控制器实例化服务,服务管理存储库,在存储库中进行CRUD操作。问题是,一旦我用我的服务中的数据填充我的网格控件(Telerik),如果我进行更新并刷新数据,则会显示旧数据而不是新数据。我认为这是我的上下文变量的持久性问题,需要处理/实例化但不太确定何时何地(工作单元变量位于服务处)。
<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
这是服务
Public Sub EditOrg(org As hdmtORG) Implements IOrgService.EditOrg
Me._context.OrgRepository.Edit(org)
Save()
End Sub
这是存储库(通用)
Public Overridable Sub Update(entity As TEntity) Implements IEntityRepository(Of TEntity).Edit
Me._objectSet.Context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified)
End Sub
有什么想法吗?
非常感谢。
答案 0 :(得分:1)
尝试使用<OutputCache(Duration:=0)> _
<OutputCache(Duration:=0)>
<HttpPost()>
<GridAction()>
Function Edit(id As Integer, name As String, clientNo As String, image As String, unit As String) As ActionResult