Asp.net mvc 3 MVC3剃须刀发动机
我使用的是mvc3剃须刀引擎 从视图中,我使用返回FilecontentResult的Uri.Action调用函数Asp.net mvc 3 MVC3剃须刀发动机,asp.net-mvc-3,Asp.net Mvc 3,我使用的是mvc3剃须刀引擎 从视图中,我使用返回FilecontentResult的Uri.Action调用函数 <img src="@Url.Action("GetImg", "Controller", new { id = Model.Id })" alt="Person Image" /> 如果byteArray为空,则函数返回null 如何从视图中知道返回了什么函数 我需要这样的东西 if(byteArray == null) <img sr
<img src="@Url.Action("GetImg", "Controller", new { id = Model.Id })" alt="Person Image" />
如果byteArray为空,则函数返回null
如何从视图中知道返回了什么函数
我需要这样的东西
if(byteArray == null)
<img src="default img" alt="Person Image" />
else
{
<a class="highslide" href="@Url.Action("GetImg", "Controller", new { id = Model.Id })" id="thumb1" onclick="return hs.expand(this)">
<img src="@Url.Action("GetImg", "Controller", new { id = Model.Id })" alt="Person Image" /> </a>
}
if(byteArray==null)
其他的
{
}
你想做什么
如果显示默认图像,则返回默认图像,而不是null
如果是更复杂的内容(例如显示上传程序或其他链接),则向模型中添加一个属性来管理它,例如PersonHasImage布尔值。您想做什么
public ActionResult GetImg(int id)
{
var byteArray = _context.Attachments.Where(x => x.Id == id).FirstOrDefault();
if (byteArray == null)
{
// we couldn't find a corresponding image for this id => fallback to the default
var defaultImage = Server.MapPath("~/images/default.png");
return File(defaultImage, "image/png");
}
return File(byteArray.Content, byteArray.Extension);
}
如果显示默认图像,则返回默认图像,而不是null
如果是更复杂的内容(例如显示上传程序或其他链接),则向模型中添加一个属性来管理它,例如PersonHasImage布尔值
public ActionResult GetImg(int id)
{
var byteArray = _context.Attachments.Where(x => x.Id == id).FirstOrDefault();
if (byteArray == null)
{
// we couldn't find a corresponding image for this id => fallback to the default
var defaultImage = Server.MapPath("~/images/default.png");
return File(defaultImage, "image/png");
}
return File(byteArray.Content, byteArray.Extension);
}
在你看来,简单地说:
<img src="@Url.Action("GetImg", "Controller", new { id = Model.Id })" alt="Person Image" />
在你看来,简单地说:
<img src="@Url.Action("GetImg", "Controller", new { id = Model.Id })" alt="Person Image" />