asp.net-mvc – 使用ASP.NET MVC在Details页面模板中显示来自数
发布时间:2020-12-16 09:15:09 所属栏目:asp.Net 来源:网络整理
导读:当我尝试使用以下内容在Details页面模板中显示byte []数组图像时: public FileContentResult RenderPhoto(byte[] photo){ // var array = (byte[])Session["photo"]; // return File(array,"image/jpeg"); return File(photo,"image/jpeg");}img src="@Url.
当我尝试使用以下内容在Details页面模板中显示byte []数组图像时:
public FileContentResult RenderPhoto(byte[] photo) { // var array = (byte[])Session["photo"]; // return File(array,"image/jpeg"); return File(photo,"image/jpeg"); } <img src="@Url.Action("RenderPhoto",Model.Photo)"/> 照片为空. 如果我在会话中存储student.Photo: // // GET: /Student/Details/5 public ViewResult Details(int id) { Student student = db.Students.Find(id); Session["photo"] = student.Photo; return View(student); } 并尝试显示从Session(上面的注释行)中检索值的图像. 为什么我在第一种情况下获得空值? 将学生传递给ViewResult详细信息(int id)中的View后,Model.Photo不再保留该值? 解决方法
您不能在< img>中将字节数组传递给服务器.标签. < img> tag只是向指定的资源发送GET请求.正确的方法是使用id: <img src="@Url.Action("RenderPhoto",new { photoId = Model.PhotoId })" /> 然后: public ActionResult RenderPhoto(int photoId) { byte[] photo = FetchPhotoFromDb(photoId); return File(photo,"image/jpeg"); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – ASP.NET MVC 4覆盖发出的html名称和id
- asp.net – aspnet_compiler找到错误版本的System.Web.WebP
- 阻止拦截ASP.NET Web API响应的FormsAuthenticationModule
- 编译ASP.NET网站时出现MSBuild错误
- asp.net-mvc-2 – 如何在Asp.net MVC2中通过Ajax调用处理Un
- asp.net-mvc – 如何使用MVC 3将文本数据导出到csv?
- 动态数据 – ASP.NET动态数据向页面添加其他过滤条件
- ASP.NET MVC 4和ExtensionlessUrlHandler
- asp.net-mvc – 使用字符串常量键来避免魔术字符串键是一个
- asp.net – 使用ninject时出现异常
推荐文章
站长推荐
热点阅读