SORU
20 Kasım 2008, PERŞEMBE


Yardımcı için < Html;ınput type="dosya" />

Dosya yükleme için bir HTMLHelper var mı? Özellikle, bir yerini arıyorum

<input type="file"/>

ASP.NET MVC kullanarak HTMLHelper.

Ya da, Eğer kullanırsam

using (Html.BeginForm())

Dosya yükleme için HTML denetimi nedir?

CEVAP
23 AĞUSTOS 2011, Salı


HTML Dosya Upload MVC 3 ASP.

Model: (FileExtensionsAttribute MvcFutures içinde kullanılabilir olduğunu unutmayın. İstemci tarafı ve sunucu tarafı dosya uzantıları doğrular.)

public class ViewModel
{
    [Required, Microsoft.Web.Mvc.FileExtensions(Extensions = "csv", 
             ErrorMessage = "Specify a CSV file. (Comma-separated values)")]
    public HttpPostedFileBase File { get; set; }
}

HTML Görünümü:

@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)
}

Denetleyicisi eylem:

[HttpPost]
public ActionResult Action(ViewModel model)
{
    if (ModelState.IsValid)
    {
        // Use your file here
        using (MemoryStream memoryStream = new MemoryStream())
        {
            model.File.InputStream.CopyTo(memoryStream);
        }
    }
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • julioissk84life

    julioissk84l

    18 ŞUBAT 2008
  • MatheusDosGames

    MatheusDosGa

    28 Aralık 2011
  • Vsauce

    Vsauce

    30 Temmuz 2007