是这样子的:主页显示所有产品目录(代码如下:)<%foreach (Product p in (IEnumerable)Model)
{ %>
<ul style=" float:left;list-style:none; text-align:center; color:Yellow;" >
<li>
<a href='<%=Url.Action("detials", "home", new {id=p.ProductID })%>'> <img src='<%=string.Format("Home/GetImage/{0}",p.ProductID)%>' alt="<%=Html.Encode(p.ProductName)%>) "
height="100px" width="100px" style=" border:0px" /></a> </li>
<li>名称:
<%=Html.Encode(p.ProductName) %></li>
<li>价格:
<%=Html.Encode(p.UnitsOnOrder) %></li>
<li>是否存货:
<%=Html.Encode(p.UnitsInStock) %></li>
</ul>
<%} %>当点击图片 察看详细情况时,跳转到detials页面(代码如下:)<h2>产品详细</h2>
<ul style=" list-style:none; text-align:left; color:Blue">
<li><img src='<%=string.Format("home/GetImage/{0}",Model.ProductID)%>' alt="" height="300" width="300"/></li>
<li>产品名称:<%=Html.Encode(Model.ProductName)%></li>
<li>提供地:<%=Html.Encode(Model.images11) %></li>
<li>价格:<%=Html.Encode(Model.UnitsOnOrder) %></li>
<li>是否存货:<%=Html.Encode(Model.UnitsInStock) %></li>
<li>质量级数:<%=Html.Encode(Model.ReorderLevel) %></li>
</ul>当跳到这个详细页面时,图片就不能显示出来。但是:当在:Global.asax页更改detials为首页时,运行就可以正常显示:这个原因 是为什么呢?GetImage 方法代码如下:
public ActionResult GetImage(int? id)
{
Product p = database.Product.Single(pr => pr.ProductID == id);
MemoryStream imageStrem = new MemoryStream(p.images.ToArray());
return new MyCompletion_MVC.Code.Helper(imageStrem, "image/jpeg");
}helper类代码:
namespace MyCompletion_MVC.Code
{
public class Helper : ActionResult
{
private MemoryStream _imageStream;
private string FileStyle;
public Helper(MemoryStream imageStream, string fileStyle)
{
_imageStream = imageStream;
FileStyle = fileStyle;
} public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
new ArgumentException("context is null");
}
if (_imageStream == null)
{
new ArgumentException(" imageStream is null");
}
if (string.IsNullOrEmpty(FileStyle))
{
new ArgumentException("FileStyle is null");
} HttpResponseBase response = context.HttpContext.Response;
response.Clear();
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.ContentType = FileStyle;
_imageStream.WriteTo(response.OutputStream);
}
}
}恳请高手帮帮小弟。。小弟无尽感激
{ %>
<ul style=" float:left;list-style:none; text-align:center; color:Yellow;" >
<li>
<a href='<%=Url.Action("detials", "home", new {id=p.ProductID })%>'> <img src='<%=string.Format("Home/GetImage/{0}",p.ProductID)%>' alt="<%=Html.Encode(p.ProductName)%>) "
height="100px" width="100px" style=" border:0px" /></a> </li>
<li>名称:
<%=Html.Encode(p.ProductName) %></li>
<li>价格:
<%=Html.Encode(p.UnitsOnOrder) %></li>
<li>是否存货:
<%=Html.Encode(p.UnitsInStock) %></li>
</ul>
<%} %>当点击图片 察看详细情况时,跳转到detials页面(代码如下:)<h2>产品详细</h2>
<ul style=" list-style:none; text-align:left; color:Blue">
<li><img src='<%=string.Format("home/GetImage/{0}",Model.ProductID)%>' alt="" height="300" width="300"/></li>
<li>产品名称:<%=Html.Encode(Model.ProductName)%></li>
<li>提供地:<%=Html.Encode(Model.images11) %></li>
<li>价格:<%=Html.Encode(Model.UnitsOnOrder) %></li>
<li>是否存货:<%=Html.Encode(Model.UnitsInStock) %></li>
<li>质量级数:<%=Html.Encode(Model.ReorderLevel) %></li>
</ul>当跳到这个详细页面时,图片就不能显示出来。但是:当在:Global.asax页更改detials为首页时,运行就可以正常显示:这个原因 是为什么呢?GetImage 方法代码如下:
public ActionResult GetImage(int? id)
{
Product p = database.Product.Single(pr => pr.ProductID == id);
MemoryStream imageStrem = new MemoryStream(p.images.ToArray());
return new MyCompletion_MVC.Code.Helper(imageStrem, "image/jpeg");
}helper类代码:
namespace MyCompletion_MVC.Code
{
public class Helper : ActionResult
{
private MemoryStream _imageStream;
private string FileStyle;
public Helper(MemoryStream imageStream, string fileStyle)
{
_imageStream = imageStream;
FileStyle = fileStyle;
} public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
new ArgumentException("context is null");
}
if (_imageStream == null)
{
new ArgumentException(" imageStream is null");
}
if (string.IsNullOrEmpty(FileStyle))
{
new ArgumentException("FileStyle is null");
} HttpResponseBase response = context.HttpContext.Response;
response.Clear();
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.ContentType = FileStyle;
_imageStream.WriteTo(response.OutputStream);
}
}
}恳请高手帮帮小弟。。小弟无尽感激
解决方案 »
- ASP.NET 加密问题 向高手们求解!!!!!
- IE7为什么两个DIV无法同行显示,IE8可以
- 如何 把从数据库中得到的image数据读取出来放到image控件中。
- 删除数据以后!页面想没用css一样
- .net关于编码转换问题
- 用最后 5 分 !! UltraWebGrid 如何 获得 某一行和某一列的 模版列控件的值 和 单元格内容 ??? 急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 字段太小而不能接受所要添加的数据的数量。试着插入或粘贴较少的数据。
- 文本框内容变化,执行事件
- 求助! 一个在网页里写的定时器,每隔20 秒向数据库存一次数据,数据从前台获得!!
- 怎样把查询数据导入到Excel显示出来?急
- 如何通过后台动态添加HTML控件
- 获取上次访问的页面
Url.Content