我想呈現FileContentResult(.png文件在我的情況)成base64字符串將它們返回到json。呈現ASP .NET MVC ActionResult字符串
我發現一個有趣的方法從這裏開始:http://approache.com/blog/render-any-aspnet-mvc-actionresult-to/,據說是在做什麼,我需要,但是當我試圖做類似
public async ActionResult GetUsers()
{
...
var query = from user in otherUsers
join file in allFiles on user.Profile.Id equals file.Profile.Id into usersWithFiles
from userWithFile in usersWithFiles.DefaultIfEmpty(new File(){Content = new byte[0], ContentType = "image/png"})
select new UserFriendModel { Id = user.Id, UserName = user.UserName, ProfileId = user.Profile.Id, File = File(userWithFile.Content, userWithFile.ContentType).Capture(ControllerContext) };
return Json(query.ToList(), JsonRequestBehavior.AllowGet);
}
我越來越
System.Web.HttpException:「使用自定義的 TextWriter時,OutputStream不可用」thrown at result.ExecuteResult(controllerContext); 一行。