- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
从过去 10 天开始,我尝试了很多在网络中提供的方法/示例/教程来解决我的问题。但是,对于所有这些情况,我都失败了。 我想上传特定/多个产品的图片,将它们保存在数据库中,并通过调用它们的 ID 在首页中显示它们。谁能为此给我逐步示例/教程/链接。 请不要给出部分答案/建议。因为我已经厌倦了这些。
最佳答案
我刚刚解决了我的问题,这里是解决方案:
这是我的模型类
public class Picture
{
public int PictureId { get; set; }
public IEnumerable<HttpPostedFile> Image { get; set; }
public string Name { get; set; }
public long Size { get; set; }
public string Path { get; set; }
}
这是我的 Controller
[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<Picture>();
var files = Directory.GetFiles(Server.MapPath("~/UploadedFiles"));
foreach(var file in files)
{
var fileInfo = new FileInfo(file);
var picture = new Picture() { Name = Path.GetFileName(file) };
picture.Size = fileInfo.Length;
picture.Path = ("~/UploadedFiles/") + Path.GetFileName(file);
uploadedFiles.Add(picture);
}
return View(uploadedFiles);
}
这是我的“索引” View
@using(Html.BeginForm("Upload", "Picture", FormMethod.Post,
new { enctype="multipart/form-data" })){
<div>
Select a file: <input type="file" name="fileUpload" />
<input type="submit" value="Upload" />
</div> }
通过这个“列表” View ,我显示了图像列表:
<table>
<tr>
<td> Name </td>
<td> Size </td>
<td> Preview </td>
</tr>
@foreach (var file in Model)
{
<tr>
<td> @file.Name </td>
<td> @file.Size </td>
<td>
<img src="@Url.Content(file.Path)"/>
</td>
</tr>
}
关于c# - 使用 Code First 方法中的 Id 从数据库上传、保存和检索图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23517615/
目前,我正在为网络开发类(class)做作业。 这些是说明:第一行和首字下沉样式Jakob 希望文章的第一行以小写大写字母显示。转到 First Line and Drop Cap Styles 部分
.first() 方法是在 jQuery 1.4 中添加的。 :first 选择器自 1.0 以来就已存在。 来自文档: :first The :first pseudo-class is equiv
我正在审查现有的 ASP.NET MVC (5.2.3) EF (6.1.3) 项目。 该项目使用 ASP.NET Identity,我检查了 web.config 中的 2 个连接字符串,一个用于
为什么人们使用 mid=first+(last-first)/2 而不是 (first+last)/2,在二进制搜索的情况下)两者有区别吗。如果有,请告诉我,因为我无法理解其中的区别。 最佳答案 如果
为什么人们使用 mid=first+(last-first)/2 而不是 (first+last)/2,在二进制搜索的情况下)两者有区别吗。如果有,请告诉我,因为我无法理解其中的区别。 最佳答案 如果
for(auto it = M.begin(); it!=M.end();it++) { coutfirstsecondsecond == 1) return it->firs
我试图从第二个循环中获取循环的第一项。 我知道我得到了这样的@key @../key 但@first 似乎不像@../first 那样工作 有什么想法吗? 问候 最佳答案 首先,无论是否在嵌套 blo
var tab1 = $('.tabs a:first-child').attr('href'); alert(tab1); .. 尽管同一页面上有两个 div.switch,但仅匹配一个。第二个位于
我想知道如何将节点*变量 NODE 分配给结构内的数据? struct node { int info; struct node *link; }; typedef struct nod
我有两个段落包含在一个 div 中。我想让第一段的文字变大一点,但使用 :first-child 并不能像我所说的那样工作。看不出有什么问题。
我有一个 ul li 列表 Parent child1 child2
我有三个表,即员工、部门和申诉。 Employees 表有超过一百万条记录。我需要找到员工的详细信息、他/她的部门以及他/她提出的申诉。 我可以想到以下两个查询来查找结果: 1。先过滤记录,只获取需要
我有三个表,即员工、部门和申诉。 Employees 表有超过一百万条记录。我需要找到员工的详细信息、他/她的部门以及他/她提出的申诉。 我可以想到以下两个查询来查找结果: 1。先过滤记录,只获取需要
这有什么区别吗: myList.Where(item => item == 0).First(); 还有这个: myList.First(item => item == 0); 后者对我来说更有意义,
我分不清 element:first-child 之间的区别和 element:first-of-type 例如,你有一个 div div:first-child → 全部 元素是其父元素的第一个子元
当我遇到一个奇怪的情况时,我正在研究 CSS 选择器。 如果我使用 :first-child 伪元素,我需要在它前面加上一个空格才能工作,否则它将无法工作。然而 :first-letter 伪元素的情
请考虑以下字符串数组: let strings = ["str1", "str2", "str10", "str20"] 假设需要获取包含 5 个字符的第一个元素 (String),我可以使用 fil
让我们假设我们要开始新项目 - 包含一些业务逻辑的应用程序、ASP.NET 上的用户界面、WPF 或两者。我们想使用 ORM 或 DAL 代码生成器并在 .NET 类中实现我们的业务逻辑。我们可以通过
我有一种树系统。我想做的是给所有 parent 一个 margin ,除了第一个。这是我的 HTML: Test
我分不清 element:first-child 之间的区别和 element:first-of-type 例如,你有一个 div div:first-child → 全部 元素是其父元素的第一个子元
我是一名优秀的程序员,十分优秀!