使用代码优先方法中的Id,从数据库上传,保存和检索图像
从过去10天开始,我尝试了许多方法/示例/教程,这些方法/示例/教程在网上提供以解决我的问题。 但是,对于所有这些情况,我失败了。 我想上传特定/多个产品的图像,将它们保存在数据库中,并通过调用它们的ID在主页中显示它们 。 任何人都可以为我提供一步一步的示例/教程/链接 。 请不要给出部分答案/建议 。 因为我已经厌倦了那些。
我刚刚解决了我的问题,这是解决方案:
这是我的模型类
public class Picture { public int PictureId { get; set; } public IEnumerable Image { get; set; } public string Name { get; set; } public long Size { get; set; } public string Path { get; set; } }
这是我的控制器
[HttpPost] public void Upload() //Here just store 'Image' in a folder in Project Directory // name 'UplodedFiles' { foreach (string file in Request.Files) { var postedFile = Request.Files[file]; postedFile.SaveAs(Server.MapPath("~/UploadedFiles/") + Path.GetFileName(postedFile.FileName)); } } public ActionResult List() //I retrive Images List by using this Controller { var uploadedFiles = new List
这是我的“索引”视图
@using(Html.BeginForm("Upload", "Picture", FormMethod.Post, new { enctype="multipart/form-data" })){ Select a file: }
通过此“列表”视图,我显示了图像列表:
上述就是C#学习教程:使用代码优先方法中的Id,从数据库上传,保存和检索图像分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
Name Size Preview @foreach (var file in Model) { @file.Name @file.Size }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/960136.html