图片分页显示

上传人:ji****72 文档编号:37678668 上传时间:2018-04-20 格式:DOC 页数:11 大小:1.03MB
返回 下载 相关 举报
图片分页显示_第1页
第1页 / 共11页
图片分页显示_第2页
第2页 / 共11页
图片分页显示_第3页
第3页 / 共11页
图片分页显示_第4页
第4页 / 共11页
图片分页显示_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《图片分页显示》由会员分享,可在线阅读,更多相关《图片分页显示(11页珍藏版)》请在金锄头文库上搜索。

1、实现:从数据库读取 image 类型的数据,在页面上显示有序列关系的图片,并完成分页显 示。涉及:vs2010 sql2008 mvc3 ef4 dwz 数据结构: 脚本:SQLQueryTypeImage.sql 用 mvc3 ef4 搭建好平台。 新建项目:开始 EF。在项目上右键:点击确定,报参数错误。 设置高级选项:生成成功:整合 dwz。搭建好了。现在可以开始图片的问题了。 实现图片在 web 下的显示: 1.添加一般处理程序,用于图片的输出:导入空间:using MvcApplicationShowImageList.Models;(数据上下文)public void Proces

2、sRequest(HttpContext context)string id = context.Request.QueryString“id“;string n = context.Request.QueryString“no“;if (string.IsNullOrEmpty(n) n = “1“;byte imagebyte;tryint Sequence_No = Int32.Parse(n);/Get image data by images IDusing (testimagexppContext db = new testimagexppContext()imagebyte =

3、db.Image_info.Where(a = a.ID = id).Where(a = a.Sequence_No = Sequence_No).Single().Medical_content;context.Response.ContentType = “image/jpg“;context.Response.BinaryWrite(imagebyte);catch (Exception Error)context.Response.Write(Error.Message);2.添加控制器在此之前,EF完之后需要编译程序,不然找不到模型类。 选择对应的类:自动生成了很多我不需要这些页面。

4、重新加一个空控制器:编写 public ActionResult Index()string id = “xpp001“;/接受酣筰d值ViewBag.id = id;using (testimagexppContext db = new testimagexppContext()var q = db.Image_info.Where(a = a.ID = id).ToList();ViewBag.totalCount =q.Count; /总哩页?数簓return View();3.在页面用 img 调用该程序,显示图片。默认显示第一页no=1。2.在 controller 控制器对应的 g

5、et 方法中绑定好需要传递的值:public ActionResult Index()string id = “xpp001“;/接受酣筰d值ViewBag.id = id;using (testimagexppContext db = new testimagexppContext()var q = db.Image_info.Where(a = a.ID = id).ToList();ViewBag.totalCount =q.Count; /总哩页?数簓return View();修改 Global.asax 来配置起始页。运行下看看,图片是否正常显示。 好正常。下面开始实现分页: 在

6、controller 里面写个 Fenye Model get 方法public ActionResult Fenye(string id, string no)ViewBag.id = id;ViewBag.currentPage = no;return View();显示页面:共 ViewData“totalCount“ 页for (int i = 1; i 第 i 页 效果图:写的不多,刚开始接触 dwz 、ef 及 mvc,还不太熟。注: 在 winform 里面处理图片是 :Bytes;MemoryStream ss = new MemoryStream(s);Bitmap news = new Bitmap(ss);public Image SetByteToImage(byte mybyte)Image image;MemoryStream mymemorystream =new MemoryStream(mybyte,0, mybyte.Length);image = Image.FromStream(mymemorystream);return image; Picturebox pic pic.Image = news;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号