1
如何上传图像以进入ASP.NET MVC 3.0中的~/Content/Images
?如何上传ASP.NET MVC中的图像?
如何上传图像以进入ASP.NET MVC 3.0中的~/Content/Images
?如何上传ASP.NET MVC中的图像?
如果你想在ASP.NET MVC中上传图片,请尝试以下问题:
如果你想使用ASP.NET控件上传图像,这打破了MVC关注的分离。有upload helpers available。
HTML文件上传ASP MVC 3
型号:(注意FileExtensionsAttribute是MvcFutures可用它会验证文件扩展名的客户端和服务器端。)
public class ViewModel
{
[Required, Microsoft.Web.Mvc.FileExtensions(Extensions = "csv", ErrorMessage = "Specify a CSV file. (Comma-separated values)")]
public HttpPostedFileBase File { get; set; }
}
HTML查看:
@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.TextBoxFor(m => m.File, new { type = "file" })
@Html.ValidationMessageFor(m => m.File)
}
控制器动作:
[HttpPost]
public ActionResult Action(ViewModel model)
{
if (ModelState.IsValid)
{
// Use your file here
using (MemoryStream memoryStream = new MemoryStream())
{
model.File.InputStream.CopyTo(memoryStream);
}
}
}
[上传使用ASP.NET MVC的图像(的可能重复http://stackoverflow.com/questions/1379558/uploading-an-image-using-asp-净MVC) – 2011-01-30 15:28:53