4 Mart 2011, Cuma
Dosya Upload ASP.NET MVC 3.0
asp.net-mvc dosya upload etmek istiyorum. Nasıl dosya input file
html kontrolü kullanarak yükleyebilir miyim?
CEVAP
4 Mart 2011, Cuma
Dosya girişi kontrol kullanmayın. Sunucu tarafı denetimleri ASP.NET MVC kullanılmaz. Çıkış following blog post hangi ASP.NET MVC bunu başarmak için nasıl gösterir.
Dosya bir giriş içeren hangi bir HTML Formu oluşturarak başlamak.:
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" value="OK" />
}
ve sonra bir denetleyici yükle işlemek gerekir:
public class HomeController : Controller
{
// This action renders the form
public ActionResult Index()
{
return View();
}
// This action handles the form POST and the upload
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
// Verify that the user selected a file
if (file != null && file.ContentLength > 0)
{
// extract only the fielname
var fileName = Path.GetFileName(file.FileName);
// store the file inside ~/App_Data/uploads folder
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
// redirect back to the index action to show the form once again
return RedirectToAction("Index");
}
}
Bunu Paylaş:
Dosya Upload kullanarak angularjs...
Nasıl bir özel entegre dosya tarayıcı/...
Nasıl bir WordPress kullanmak upload d...
test dosya upload rspec kullanarak ray...
MVC 4 Razor Dosya Upload...