سؤال

أحاول إضافة تحميل ملف buiimp إلى تطبيق MVC وأناامتلاك مشاكل في تلقي الملفات في إجراءات المشاركة (IM الذهاب إلى وظيفة تحميل الملفات المتعددة) .كان شخص ما الرجاء مساعدتي في معرفة ذلك؟

في رأيي لدي التعليمات البرمجية التالية: giveacodicetagpre.

رمز jQuery للحصول على تحميل ملف buiimp هو ما يلي: giveacodicetagpre.

وداخل وحدة التحكم طريقة الإجراء التالية: giveacodicetagpre.

أنا أستخدم MVC 3.

في طريقة الإجراء، إذا كانت الوسيطة من النوع IEnaryable، فإنه يتلقى NULL

أي نوع من المساعدة موضع تقدير كبير، شكرا.

هتافات

هل كانت مفيدة؟

المحلول

The SaveFile controller action will be called for each file. So it should look like this:

[HttpPost]
public ActionResult SaveFile(HttpPostedFileBase file)
{
    //some file upload magic

    // return JSON
    return Json(new
    {
        name = "picture.jpg",
        type = "image/jpeg",
        size = 123456789
    });
}

And if you want to handle multiple upload files in the same request you may take a look at the respective section of the documentation.

نصائح أخرى

To get the files you could use,

foreach (string inputTagName in Request.Files)
{                
    HttpPostedFileBase file = Request.Files[inputTagName];
}

I know that this is an old issue, but just to point in here. In addition to Darin Dimitrov post - returned json should be in format compatible with jQuery File Upload - which expects array even if one file is transmitted. For example:

        return Json(
            new
            {
                files = new[]{
                                new { 
                                        name = "www.png",
                                        size = "1234567"
                                    }
                              }
            }
        );
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top