File upload with ajax in asp.net mvc

前端 未结 4 1332
遇见更好的自我
遇见更好的自我 2020-12-22 01:23

I know this has been discussed a lot of times.

I basically want the possibility in my view to update a file. This file has to be mapped to the model the controller e

相关标签:
4条回答
  • 2020-12-22 01:43

    I think you cannot upload files with AJAX. One way to achieve this is to use a hidden iframe. Try this jQuery Form plugin and Telerik file control

    Please refer this link also.

    0 讨论(0)
  • 2020-12-22 01:56

    Try this code

    //Add reference to form.js

    <script src="http://malsup.github.com/jquery.form.js"></script>
    
    @using (Html.BeginForm("Create", "Company", FormMethod.Post, new { @enctype ="multipart/form-data",@id="formid" }))
    {
    
    }
    
    //Javascript code
    
    <script type="text/javascript">
    
    $('#formid').ajaxForm(function (data) {
    
    });
    
    </script>
    

    This will work as ajax submit.

    //You can get more details on AjaxForm here

    0 讨论(0)
  • 2020-12-22 01:59

    I have made it based on this answer from Demian Flavius: How to do a ASP.NET MVC Ajax form post with multipart/form-data?

    Basically it's the new JavaScript's FormData object that makes it easy for uploading with ajax as in the article your mentioned.

    0 讨论(0)
  • 2020-12-22 02:04

    Please try this one @using (Html.BeginForm("Create", "Company", FormMethod.Post, new { id = "ym-form", enctype="multipart/form-data" }))

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