Asp.net mvc MVC数据库映像和默认映像

Asp.net mvc MVC数据库映像和默认映像,asp.net-mvc,filecontentresult,Asp.net Mvc,Filecontentresult,从数据库中获取以下图像 <img src="@Url.Action("GetLogo", "Logo", new { ID = 16})" /> 在没有数据库记录之前,这一切都可以正常工作-如果是这种情况,那么我希望返回默认图像(例如),但由于上面的控制器返回FileContentResult,我遇到了一些困难 任何帮助都将不胜感激 public FileContentResult GetLogo(int ID) { var GetImage = (from x in re

从数据库中获取以下图像

<img src="@Url.Action("GetLogo", "Logo", new { ID = 16})" />
在没有数据库记录之前,这一切都可以正常工作-如果是这种情况,那么我希望返回默认图像(例如
),但由于上面的控制器返回
FileContentResult
,我遇到了一些困难

任何帮助都将不胜感激

public FileContentResult GetLogo(int ID)
{
    var GetImage = (from x in repository.GetClientLogo
                    where x.ClientID == ClientID
                    select x).FirstOrDefault();
    if (GetImage == null)
    {
      return File(Server.MapPath("/Images/NoLogo.jpg"), "image/jpeg");
    }

    ClientLogo clientLogo = GetImage;
    return File(clientLogo.ImageData, clientLogo.ImageMimeType);
}
当您找不到客户端的映像时,只需返回NoLogo文件


当您找不到客户端的映像时,只需返回NoLogo文件

很抱歉,它现在抛出错误:无法将System.Web.Mvc.FilePathResult转换为System.Web.Mvc.FileContentResultGot-将返回类型从FileContentResult更改为ActionResult,然后执行了。。。。返回(ActionResult)文件(“../Content/Images/General/bigtick.jpg”,“image/jpg”);}else{ClientLogo ClientLogo=GetImage;返回(ActionResult)文件(ClientLogo.ImageData,ClientLogo.ImageMimeType);您甚至不需要将返回类型转换为ActionResult,因为FileContentResult和FilePathResult都是ActionResult的后代。因此,它现在抛出了一个错误:无法将System.Web.Mvc.FilePathResult转换为System.Web.Mvc.FileContentResultGot它-将返回类型从FileContentResult更改为ActionResult,然后…return(ActionResult)文件(“../Content/Images/General/bigtick.jpg”,“image/jpg”);}else{ClientLogo ClientLogo=GetImage;return(ActionResult)文件(ClientLogo.ImageData,ClientLogo.ImageMimeType);甚至不需要将返回类型转换为ActionResult,因为filecontentnttresult和FilePathResult都是ActionResult的后代
public FileContentResult GetLogo(int ID)
{
    var GetImage = (from x in repository.GetClientLogo
                    where x.ClientID == ClientID
                    select x).FirstOrDefault();
    if (GetImage == null)
    {
      return File(Server.MapPath("/Images/NoLogo.jpg"), "image/jpeg");
    }

    ClientLogo clientLogo = GetImage;
    return File(clientLogo.ImageData, clientLogo.ImageMimeType);
}