Asp.net mvc Krajee引导文件输入显示数据库中的图像

Asp.net mvc Krajee引导文件输入显示数据库中的图像,asp.net-mvc,image,twitter-bootstrap,asp.net-mvc-4,Asp.net Mvc,Image,Twitter Bootstrap,Asp.net Mvc 4,我在员工注册过程中使用插件上传图像。图像保存到项目中的一个文件夹中,路径保存到数据库中 编辑员工时,我想显示从数据库上传的图像 我的问题是如何显示数据库中的图像 数据库结构为 EmployeeId PhotoUrl 1 ~/UploadImages/Employee/Photo/Emp1.jpg 我从网站上得到了示例代码 $(document).on('ready', function() { $("#input-24").fileinput({

我在员工注册过程中使用插件上传图像。图像保存到项目中的一个文件夹中,路径保存到数据库中

编辑员工时,我想显示从数据库上传的图像

我的问题是如何显示数据库中的图像

数据库结构为

EmployeeId        PhotoUrl

   1             ~/UploadImages/Employee/Photo/Emp1.jpg
我从网站上得到了示例代码

$(document).on('ready', function() {
$("#input-24").fileinput({
    initialPreview: [
        '<img src="/images/moon.jpg" class="file-preview-image" alt="The Moon" title="The Moon">',
        '<img src="/images/earth.jpg" class="file-preview-image" alt="The Earth" title="The Earth">'
    ],
    overwriteInitial: false,
    maxFileSize: 100,
    initialCaption: "The Moon and the Earth"
});
JQuery用于调用fileInput

//fileUpload plugin
$(".imgUpload").fileinput({
    showUpload: false,
   //How can I set value here
    initialPreview: [
        '<img src="~/UploadImages/Employee/AddressProof/Emp16.jpg" class="file-preview-image" alt="The Moon" title="The Moon">'           
    ],
    overwriteInitial: false,
    initialCaption: "Emp16.jpg"
});
//文件上传插件
$(“.imgUpload”).fileinput({
showUpload:false,
//如何在此处设置值
初始预览:[
''           
],
覆盖初始值:false,
首字母标题:“Emp16.jpg”
});

要分配初始图像,可以使用

$(".imgUpload").fileinput({
  showUpload: false,
  initialPreview: [
    '<img src="@Model.PhotoUrl" class="file-preview-image" .... >'           
  ],
  ....
});
然后POST方法将包含上传文件的参数

[HttpPost]
public ActionResult Edit(Employee model, HttpPostedFileBase photoFile)
或者更好,使用包含url和文件属性的视图模型

public class EmployeeVM
{
  public string PhotoUrl { get; set; }
  public HttpPostedFileBase PhotoFile { get; set; }
  .... // other properties
}
在我看来

@Html.TextBoxFor(m => m.PhotoFile, new { type = "file", @class = "imgUpload" })

您是否有员工的模型/视图模型?它应该包含一个属性,比如说
IEnumerable PhotoUrl
,用于url的集合,以便您可以在视图中分配它们。好的,我明白了。我必须在视图中创建一个单独的
图像标记
,并将
src
设置为
PhotoUrl
。可以通过上述文件输入本身显示图像吗?员工可以有多个图像(或只有一个)吗?哦,忘了说
谢谢您的关注
:)。员工只能显示一个图像。在这种情况下,您可能只需要
初始预览:[']
假设您的模型具有属性
字符串PhotoUrl
public class EmployeeVM
{
  public string PhotoUrl { get; set; }
  public HttpPostedFileBase PhotoFile { get; set; }
  .... // other properties
}
@Html.TextBoxFor(m => m.PhotoFile, new { type = "file", @class = "imgUpload" })