I'm looking to implement a file upload that logged in members can use to create simple content (Adverts, Photo Galleries etc).
These are members, not users, so the upload needs to be done via .net code. I'm trying to implement this with a surface controller, however I'm stuck.
I want to use a HTML5 file input type on the form. I can't work out how to get hold of that in my controller code.
I've created a view model, and I've created a strongly typed "edit" view which passes though a FormColletion. However the file selected by the user is not part of that collection, other form elements are there, but not the file.
I guess I have 2 questions.
1. Am I going about this the right way (I'm new to Umbraco)
2. How do I get the user selected file into my controller code?
I've updated my model to use the HttpPostedFileBase (it was previously using a string to hold the umbraco media file path once it is saved as content), and I've changed the controller action method signature from
public ActionResult Edit(int id, FormCollection collection)
to
public ActionResult Edit(myViewModel model)
I can now get a hold on the uploaded file in my controller, and upload it to Umbraco from there. Awesome. :)
I'm currently using a typedPartial view for the edit screen - seems to be working OK. I haven't done much more than use the Visual Studio auto generated scaffold view. I'll beautify it after I get the logic written.
File upload from members - Umbraco 7
Hi All,
I'm looking to implement a file upload that logged in members can use to create simple content (Adverts, Photo Galleries etc).
These are members, not users, so the upload needs to be done via .net code. I'm trying to implement this with a surface controller, however I'm stuck.
I want to use a HTML5 file input type on the form. I can't work out how to get hold of that in my controller code.
I've created a view model, and I've created a strongly typed "edit" view which passes though a FormColletion. However the file selected by the user is not part of that collection, other form elements are there, but not the file.
I guess I have 2 questions. 1. Am I going about this the right way (I'm new to Umbraco) 2. How do I get the user selected file into my controller code?
Hi Paul,
I alrady experienced this behaviour. Tell me if I'm wrong:
If it is so could you try to move the whole form into a typed partial and put the partial into your not typed view?
I had the same issue (I honestly don't know if it's a bug or not) and this worked for me.
BR,
Stefano
Many thanks Stefano.
I think I'm getting closer. After posting the question here I decided to try a different tack and look at this as a Razor problem, rather than an Umbraco one. I found this article: http://stackoverflow.com/questions/304617/html-helper-for-input-type-file
I've updated my model to use the HttpPostedFileBase (it was previously using a string to hold the umbraco media file path once it is saved as content), and I've changed the controller action method signature from
to
I can now get a hold on the uploaded file in my controller, and upload it to Umbraco from there. Awesome. :)
I'm currently using a typedPartial view for the edit screen - seems to be working OK. I haven't done much more than use the Visual Studio auto generated scaffold view. I'll beautify it after I get the logic written.
Many thanks for your help.
is working on a reply...