SORU
8 NİSAN 2009, ÇARŞAMBA


Nasıl MVC denetleyicisi indirmek için bir dosya takdim edebilir miyim?

WebForms, normalde bu gibi bir kod tarayıcı mevcut izin verecek bir "Dosya Yükleme" açılan bir PDF ve bir dosya adı gibi rasgele bir dosya türü,:

Response.Clear()
Response.ClearHeaders()
''# Send the file to the output stream
Response.Buffer = True

Response.AddHeader("Content-Length", pdfData.Length.ToString())
Response.AddHeader("Content-Disposition", "attachment; filename= " & Server.HtmlEncode(filename))

''# Set the output stream to the correct content type (PDF).
Response.ContentType = "application/pdf"

''# Output the file
Response.BinaryWrite(pdfData)

''# Flushing the Response to display the serialized data
''# to the client browser.
Response.Flush()
Response.End()

Nasıl ASP.NET MVC, aynı görevi gerçekleştirmek muyum?

CEVAP
8 NİSAN 2009, ÇARŞAMBA


Bir FileResult iade veya eylem, dosyanın var olup olmadığını bağlı olarak FileStreamResult veya anında yaratabilirsiniz.

public ActionResult GetPdf(string filename)
{
    return File(filename, "application/pdf", Server.UrlEncode(filename));
}

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • BigDawsVlogs

    BigDawsVlogs

    17 HAZİRAN 2013
  • Hallucination Land

    Hallucinatio

    14 Ocak 2011
  • Jeremy Gallman

    Jeremy Gallm

    11 NİSAN 2012