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,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.
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
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"
);
);
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