我只需要显示插入的多个图像 [英] I need just to display the multiple images I insert

查看:89
本文介绍了我只需要显示插入的多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要显示插入的多张图像,将其保存在路径中,但是当他显示时确实会显示出来.我不知道我的问题在哪里,但这是我的代码,请大家帮我?

I need just to display the multiple images I insert it save will in path, but when he showed it does show up. I don't know where is my problem but this is my code please guys help me?

我的控制器

public async Task<ActionResult> Create(Inbox model, IEnumerable<HttpPostedFileBase> files)
{
    var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
    if (ModelState.IsValid)
    {
        model.User = currentUser;
        foreach (var file in files)
        {
            if (file != null && file.ContentLength > 0)
            {
                var fileName = Path.GetFileName(file.FileName);
                var path = Path.Combine(Server.MapPath("~/FilesAPP"), fileName);
                file.SaveAs(path);
                path = Url.Content(Path.Combine("~/FilesAPP", fileName));
            }
        }
        db.Inboxs.Add(model);
        db.SaveChanges();
        string url = Url.Action("List");
        return Json(new { success = true, url = url });
    }
    return View(model);
}

我的模特

public string Files { get; set; }

我的观点

<img width="200" height="150" src="@Url.Content(Model.Files))" />

如何显示我的图像人?

推荐答案

首先为文件创建列表

    public async Task<ActionResult> Create(Inbox model, IEnumerable<HttpPostedFileBase> files)
        {
List<Inbox>lst=new List<Inbox>();
            var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
            if (ModelState.IsValid)
            {
                model.User = currentUser;
                foreach (var file in files)
                {
                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        var path = Path.Combine(Server.MapPath("~/FilesAPP"), fileName);
                        file.SaveAs(path);
                        path = Url.Content(Path.Combine("~/FilesAPP", fileName));
lst.add(new Inbox{Files=path});
//you files added here
                    }
                }
                db.Inboxs.Add(model);
                db.SaveChanges();
                string url = Url.Action("List");
                return Json(new { success = true, url = url });
            }
            return View(model);
        }

您认为之后

@model List<Inbox>

@foreach (var item in Model.Files)
{
    <img src="@item.FilePath" />
}

这篇关于我只需要显示插入的多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆