+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / Upload File with MVC

Upload File with MVC

11 posts, 0 answered
  1. Pascal
    Pascal avatar
    9 posts
    Registered:
    22 Nov 2010
    27 Aug 2012
    Link to this post

    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




     

  2. Loc
    Loc avatar
    1 posts
    Registered:
    27 Aug 2012
    09 Jan 2013
    Link to this post

    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.

  3. Kristian Smilenov
    Kristian Smilenov avatar
    32 posts
    Registered:
    18 Mar 2015
    10 Jan 2013
    Link to this post
    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
  4. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    08 Dec 2016
    26 Mar 2013
    Link to this post
    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
  5. Bob
    Bob avatar
    25 posts
    Registered:
    14 Aug 2012
    24 Apr 2013
    Link to this post
    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
  6. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    08 Dec 2016
    29 Apr 2013
    Link to this post
    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
  7. Jonathan
    Jonathan avatar
    119 posts
    Registered:
    19 Dec 2012
    20 Dec 2013 in reply to Stanislav Velikov
    Link to this post
    Using KendoUI worked for me, thanks!

    Happy Coding This!
  8. Jonathan
    Jonathan avatar
    119 posts
    Registered:
    19 Dec 2012
    30 Dec 2013 in reply to Jonathan
    Link to this post
    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 
  9. Jamie
    Jamie avatar
    25 posts
    Registered:
    07 Aug 2012
    28 Jan 2014
    Link to this post
    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];
        // ....
    }
  10. Dustin
    Dustin avatar
    2 posts
    Registered:
    07 Jul 2010
    10 Jul 2014
    Link to this post

    So is it true that there is no supported way to upload files in Sitefinity from an MVC widget?

  11. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    08 Dec 2016
    15 Jul 2014
    Link to this post
    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
     
11 posts, 0 answered