0

asp.net MVC2プロジェクトでpluploadを使用しようとしていますが、使用できますか?できれば助けてください。

よろしくお願いします!

4

1 に答える 1

0

通常のファイルアップロードと同じですが、プロジェクトで使用するpluploadが好きなので、次のコードがpluploadで機能します

[HttpPost]
    public ActionResult Create(FormCollection collection)
    {
        // my project need single file upload so i get the first file
        // also you can write foreach statement to get all files
        HttpPostedFileBase postedFile = Request.Files[0];
        Image image = new Image();
        if (TryUpdateModel(image))
        {
            fRepository.AddImage(image);
            fRepository.Save();

            // Try to save file
            if (postedFile.ContentLength > 0)
            {
                string savePath = Path.Combine(Server.MapPath("~/Content/OtelImages/"), image.ImageID.ToString() +
                                                   Path.GetExtension(postedFile.FileName));
                postedFile.SaveAs(savePath);

                // Path for dbase
                image.Path = Path.Combine("Content/OtelImages/", image.ImageID.ToString() +
                                                   Path.GetExtension(postedFile.FileName));
            }

コードは変更していませんが、さらにサポートが必要な場合は、お問い合わせください。説明します。

于 2011-08-23T04:23:11.430 に答える