我正在开发一个多语言漫画网站,所有插入的漫画必须用英语和葡萄牙语。
我成功地管理了多个标题,这样做:
ComicViewModel.cs:
public class ComicViewModel
{
[Key]
public int Id { get; set; }
[Required(ErrorMessage="A data não pode ficar em branco.")]
[DisplayName("Data")]
public DateTime Date { get; set; }
public IList<LocalizedTextViewModel> Titles { get; set; }
}LocalizedTextViewModel.cs:
public class LocalizedTextViewModel
{
public CultureViewModel Culture { get; set; }
[Required(ErrorMessage = "Este campo não pode ficar em branco.")]
public string Text { get; set; }
}CultureViewModel.cs:
public class CultureViewModel
{
public int Id { get; set; }
public string Abbreviation { get; set; }
public string Name { get; set; }
public CultureViewModel() { }
public CultureViewModel(Database.Culture culture)
{
Id = culture.Id;
Abbreviation = culture.Abbreviation;
Name = culture.Name;
}
}问题是我不知道如何管理漫画图片上传。我需要上传一个以上的图片,每一个参考它的语言。
有人有什么想法吗?
发布于 2010-09-13 14:23:40
下面是一个上传多个文件的示例:
Html:
<% using (Html.BeginForm("Upload", "File", FormMethod.Post, new { enctype = "multipart/form-data" }))
{%><br />
<input type="file" name="files" id="file1" size="25" />
<input type="file" name="files" id="file2" size="25" />
<input type="submit" value="Upload file" />
<% } %> 财务主任:
[HttpPost]
public ActionResult Upload()
{
foreach (string inputTagName in Request.Files)
{
HttpPostedFileBase file = Request.Files[inputTagName];
if (file.ContentLength > 0)
{
string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads")
, Path.GetFileName(file.FileName));
file.SaveAs(filePath);
}
}
return RedirectToAction("Index");
}更新:获取有关上传的文件的一些信息
下面的示例演示如何获取提交的HttpPostedFileBase文件的名称/类型/大小/扩展名。
string filename = Path.GetFileName(file.FileName);
string type = file.ContentType;
string extension = Path.GetExtension(file.FileName).ToLower();
float sizeInKB = ((float)file.ContentLength) / 1024;假设您上传了文件somePicture.jpeg,输出将是。
filename > somePicture.jpeg
type > image/jpeg
extension > jpeg
sizeInKB > // the file size.https://stackoverflow.com/questions/3700340
复制相似问题