Upload File with MVC - Bugs & Issues - Bugs & Issues - Progress Community
 Bugs & Issues

Upload File with MVC

  • Upload File with MVC
  • Hi,

    my View does not render properly:
    @using Telerik.Sitefinity.UI.MVC

     <h2>FileUpload</h2>

     @using (@Html.BeginFormSitefinity("FileUpload","FileUpload",

     FormMethod.Post, new enctype = "multipart/form-data" ))

     

         <input name="FileUpload" id="FileUpload" type="file" />

         <input type="submit" value="Upload File" />

     

    now the div around the upload area gets the enctype attribute which is wrong
    <div id="FileUpload" enctype="multipart/form-data">       
    <input name="FileUpload" id="FileUpload" type="file" />

    <input type="submit" value="Upload File" />.....

    the form should have this attribute but it doesn't
    <form method="post" action="test-mvc" id="aspnetForm">

    Why is that?

    Thanks for help




     

  • I am also having the same issue for a hybrid mode template. The enctype="multipart/form-data is in the div instead of the form. My fileUpload returns as a null.

    But if I use pure MVC mode as my template, It works as it should.

  • Hello
    Loc,

    When you use Mvc only mode you have complete control over the markup and how the content from the controllers is rendered. When you are in Hybrid mode Sitefinity always generates one default form for the page and all widgets are rendered in this form. Using the standard syntax generated one more form tag which is not valid html. Because of this when in hybrid mode BeginFormSitefinity renders a div element.

    Kind regards,
    Kristian Smilenov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • c60e8806-3c8c-45bd-8d78-810c0e5be1a6_Mvc-KendoUpload.zip
    Hi,

     The problem is that the file stream that is to be uploaded is not passed with success from the sitefinity form back to the controller. Using MVC in sitefinity is managed by a complex form as when placing MVC widget on sitefintiy page (hybrid and pure mode) the widget form is placed into sitefinity form and the form becomes complex. A custom http handler is needed to handle the upload in this case.
    The basic sample for MVC will not work as a handler will be needed to pass the posted file to the controller inside the complex form.

    For this use a MVC control that have handler implemented to handle such scenario, use kendoUI for asp.net mvc. Using Kendo Upload control the file to be uploaded is passed from the view to the controller with success using HttpPostedFileBase.

    Attached is a sample uplod control using Keno, here is the documentation for using kendo in a project.

    Regards,
    Stanislav Velikov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Hello,

    another way to fix this, is by creating a template based on a masterpage, and add manually enctype="multipart/form-data" to the form tag (on this masterpage).

    kind regards
  • Hi,

    Thank you for sharing this.

    Regards,
    Stanislav Velikov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Using KendoUI worked for me, thanks!

    Happy Coding This!
  • Well after a week of the kendoUI stop working for me :( 

    So in my [HttpPost] action i was able to grab the input stream from Request.Files["FieldName"] there is probably alot wrong with this but its working as of now 
  • This topic helped me a lot. I ended up setting the encoding in the view using jQuery:

    $(document).ready(function ()
        $('form').attr("enctype", "multipart/form-data").attr("encoding", "multipart/form-data");
    );

    Then in the action iterating over the files which are be of type HttpPostedFileBase

    foreach (string fileName in Request.Files)
        var file = Request.Files[fileName];
        // ....
  • So is it true that there is no supported way to upload files in Sitefinity from an MVC widget?

  • Hello,

    Sitefinity supports fully the upload in Pure (MVC only) mode out of the box. In Pure mode you can have as many as you want forms and upload freely as in an MVC application. However, in hybrid mode this is not possible for the reasons already described by my colleagues in the previous replies. You can use the suggested Kendo file upload control for the upload or add a Sitefinity form with our file upload for hybrid mode.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items