I’m using mvc3 razor engine
from view I call function with Uri.Action which return FilecontentResult
<img src="@Url.Action("GetImg", "Controller", new { id = Model.Id })" alt="Person Image" />
Function:
public FileContentResult GetImg(int id)
{
var byteArray = _context.Attachments.Where(x => x.Id == id).FirstOrDefault();
if (byteArray != null)
{
return new FileContentResult(byteArray.Content, byteArray.Extension);
}
return null;
}
if byteArray is empty function returns null
how to know from view what returned function?
I need something like this
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>
}
and in your view simply:
or if you write a custom HTML helper to generate this
<img>tag even simpler: