我正在尝试检索存储在SQL Server中的jpeg文件,并使用img src =“ filepath”将这些文件呈现为html,但是我的C#代码返回的是实际图像,而不是图像的URL路径,这只会显示一个带有x在里面。
如何直接将图像显示为图像变量。这是带有Razor C#的HTML页面:
@{
int iFileID = 8;
string sPhotoDesc = "";
Image iPhotoImage = null;
}
<form>
<fieldset>
<legend>FileInput</legend>
<input type="file" id="fileinput" />
<input type='button' id='btnLoad' value='Load' onclick="@{iPhotoImage =
PhotoLibraryApp.PhotoData.SelectPhoto(iFileID, out sPhotoDesc); }">
<div id="editor"></div>
</fieldset>
<img src="@iPhotoImage" width="500" height="377">
以下是名为PhotoData.cs的单独文件中的相关C#代码:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Drawing;
using System.IO;
using System.Transactions;
namespace PhotoLibraryApp
{
public class PhotoData
{
private const string ConnStr =
"Data Source=.;Integrated Security=True;Initial
Catalog=PhotoLibrary;";
public static Image SelectPhoto(int photoId, out string desc)
{
const string SelectTSql = @"
SELECT
Description,
Photo.PathName(),
GET_FILESTREAM_TRANSACTION_CONTEXT()
FROM PhotoAlbum
WHERE PhotoId = @PhotoId";
Image photo;
string serverPath;
byte[] serverTxn;
慕哥9229398
相关分类