图像绑定MVC actionresult razor view

时间:2016-02-07 08:14:16

标签: asp.net-mvc-4

大家好我绑定了img标签,如下所示

<img alt="" src='@Url.Action("UserImage", "Home")' class="avatar img-circle img-thumbnail" />

这是我从数据库中获取图像的代码

[HttpGet]
    public ActionResult UserImage()
    {
        string user = Session["UserName"] as string;
        byte[] photo = null;
        var v = db.table.Where(p => p.USER_NAME == user).Select(img => img.PHOTO).FirstOrDefault();
        if (v != null)
        {
            photo = v;
            return File(photo, "image/jpeg");
        }
        else
            return null;
    }

当我在数据库中时显示图像但是当它为null时它显示如下,而不是我需要将src标记绑定为空

enter image description here

0 个答案:

没有答案