Upload Image MVC always null

后端 未结 3 1397
生来不讨喜
生来不讨喜 2021-01-24 00:44

Hi everyone i am trying to upload a simple image but the HttpPostedFileBase is always remaining null. This is my code i dont know what i am doing wrong.

This is my code

相关标签:
3条回答
  • 2021-01-24 01:00

    Can anyone please tell me what is the problem??

    There's nothing wrong with the code you have shown. I suspect that the problem comes from the fact that you are submitting this form using an AJAX call and not a normal submit. But as you know you cannot upload files using AJAX. That's why your code is not working. If you want to upload files using AJAX you could use some client side plugin such as Uploadify or Fine uploader. This can also be done natively in HTML5 using the new File API. Of course this will only work in modern browsers that support it. If you need to support legacy browsers some of the available client side upload plugins might help you.

    0 讨论(0)
  • 2021-01-24 01:17

    This was driving me crazy too. After hours I realized, that

    @Scripts.Render( "~/bundles/jquerymobile")

    in _Layout.cshtml was causing the problem. When commented out, the upload worked.

    See http://forum.jquery.com/topic/jquery-mobile-seems-to-clobber-ability-to-upload-files-via-forms for details.

    Adding

    data_ajax="false"
    attribute to my form solved the problem.

    0 讨论(0)
  • 2021-01-24 01:17

    Be sure model.File1 type is HttpPostedFileBase not HttpPostedFile and form contains enctype = "multipart/form-data" attribute.

    0 讨论(0)
提交回复
热议问题