【发布时间】:2011-10-02 21:36:49
【问题描述】:
How to show image in jqgrid in edit mode 的代码用于在 jqgrid 中显示图像。
如果行被更新(编辑动作是控制器被调用),行图像在服务器中改变:图像 url 保持不变,但在行保存后从服务器返回新图像。
jqgrid 仍然显示旧图像:它不向服务器请求新图像。按下网格刷新按钮也不会请求新图像。按浏览器刷新按钮检索新图像,但这很不方便。
如何在 jqgrid 中更新行后显示新图像?
更新
我按照 Oleg 的建议添加了 outputcache 属性。使用提琴手,我验证了来自图像调用的图像响应标头
GET http://localhost:50076/erp/Grid/GetImage?_entity=Artpilt&size=54&id=734 HTTP/1.1
Accept: image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5
Referer: http://localhost:50076/erp/Grid?_entity=Artpilt
Accept-Language: et-EE
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept-Encoding: gzip, deflate
Host: localhost:50076
If-Modified-Since: Mon, 03 Oct 2011 11:25:29 GMT
If-None-Match: "ArtPilt734"
Connection: Keep-Alive
Cookie: .MyAuth=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
是:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Mon, 03 Oct 2011 11:17:46 GMT
X-AspNet-Version: 2.0.50727
X-AspNetMvc-Version: 2.0
Cache-Control: public, max-age=0, s-maxage=0
Expires: Mon, 03 Oct 2011 11:17:46 GMT
Last-Modified: Mon, 03 Oct 2011 11:17:46 GMT
ETag: "ArtPilt734"
Content-Type: image/jpeg
Content-Length: 1444
Connection: Close
如果编辑表单中的数据被更改并保存,旧图像仍然存在。 fiddler 显示未从服务器检索到 tmage。
如果编辑表单关闭,旧图像显示在网格中。在 jqgrid 工具栏中按下 jqgrid 刷新按钮会导致旧图像仍然显示。 Fiddler 显示新的图像请求不是没有从服务器读取。只有在浏览器中按 F5 才能检索新图像。
如果编辑表单中的行数据发生变化,如何立即刷新图像?
更新2 我认为 Oleg 的意思是 HttpCacheability.NoCache ,而不是他在评论中写的 HttpCacheability.Private 。
我将 MVC2 控制器更改为
[OutputCache(Duration = 0, VaryByParam = "")]
public FileContentResult GetImage(string _entity, int id, int? size)
{
HttpContext.Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetMaxAge(new TimeSpan(0));
... retrieving image and fileextension form database skipped ...
HttpContext.Response.Cache.SetETag("\"ArtPilt" + id.ToString() + "\"");
return File(image, "image/" + imagetype );
}
respose 头是
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Mon, 03 Oct 2011 13:10:35 GMT
X-AspNet-Version: 2.0.50727
X-AspNetMvc-Version: 2.0
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Content-Type: image/jpeg
Content-Length: 1457
Connection: Close
但问题仍然存在。 Fiddler 显示没有检索到当前行图像。
【问题讨论】:
-
如果您使用 Firebug 或其他 Web 调试器并在保存行后检查网格的 HTML,您是否在 IMG 元素中看到新图像的 URL?
-
@Walter:URL 始终相同。如更新的答案所示,这是包含行 ID 的动态 url。 GetImage 从相同的 url 返回不同的图像。 GetImage 检查行数据并根据行数据返回图像。如果行数据已更改,则行中实际上存在图像列。 Getimage 从数据库中返回该行列值
标签: jqgrid