Multiple file uploads asp.net mvc - asp.net-mvc

I am facing one serious problem
Technology: Asp.net mvc
I am trying to upload multiple files from the dynamically created file upload control from
javascript.(Attach more file Options).My files are not getting posted to the mvc controller action.i have specified the propert new { enctype = "multipart/form-data" } in my form
still the file is not getting posted.
NB:
1)The file from the first file upload control(which is shown on the first page load is getting posted but the rest which is added using attach more file option is not getting posted)
Many Thanks in advance.

I am using with asp.net mvc for multiple file upload this jquery plugin and it works well: http://www.fyneworks.com/jquery/multiple-file-upload/
In the view you have to include something like this:
<input name="attachments" type="file"/>
And then you have to make an action method in the controller that waits for List<HttpPostedFileBase> attachments
If you can not make your current solution to work this plugin worth a try....

MVC has no built-in way to upload multiple files at once, other than to have multiple <input type="file" /> elements in your page.
You will probably want something a little more advanced, so you can use any number of jQuery plugins that do this, such as http://www.fyneworks.com/jquery/multiple-file-upload or http://www.uploadify.com/
Once the files are uploaded, then you can convert them to thumbnails using any of a number of techniques, some using third party libraries, some using built-in code.. there's lots out there if you look for them.
Here's a nice tutorial with a lot of what you need.
http://www.codeproject.com/Articles/379980/Fancy-ASP-NET-MVC-Image-Uploader

Related

use of partial views (file upload forms on different pages)

I am very new to asp.net MVC.
I need to create dnd file "component". It allows user to upload file to server using DnD, the upload is done via webAPI. I am using FileModel here, for example, webApi also returns FileModel (to show uploaded file info on page). I did this part.
However, I did it in the "TestView". I need ability to add this "component" to any view on my project. Unfourtunately I do not have knowledge enough to do this.
I have found out that there are PartialViews. Should I just move my "TestView" to some "FileUploadPartialView"? What problems this will cause? How this affect the usage of FileModel?
Partial Views are like a javascript include. You shouldn't have any trouble.
Just put this wherever you need to have your partial view...
#Html.Partial("_FileUploadPartialView")
Let me know if you need more detail.

Images Not Showing in MVC

I am working on MVC4 project and facing a problem.The project on which i am working was developed in web forms.The html of pages is already saved in Database.I am getting this html from DB and showing it on Views. Now the problem is that this Html aslo contains Images and links and these are working fine in web forms application but in MVC images and links are not working i.e images fail to load due to invalid path although i have made the same folder structure. Here is an example.
Suppose i have an image in folder App_Themes/Theme1/Img/download_icon.gif. Now in MVC project if i give this image the src like /App_Themes/Theme1/Img/download_icon.gif it is loaded correctly but if i give it the src like App_Themes/Theme1/Img/download_icon.gif it does not load and this is saved in Db. My question is how can i load all images correctly that come from Db in html?
You got a tricky scenario. Its always a bad practice to keep Html tags in database because it may cause these kind of issues in future, which gives head aches to current developer working on that. As per my opinion there is no solution, but I am suggesting a work around for you to overcome this. This is an issue with virtual directory and hope that we can resloved by Url.content.
Any way your are getting the html from database. So I believe that you have something similar to this.
string htmlContent = getHtmlforPage1()
it will returns you all the html for page one and you use HtmlString() to show it in your view.
You can replace the <img src=blah\blah.img /> with "<img src="+ Url.Content(blah\blah.img") />. all you need is to write down a function to achieve this.
This question will gives you about the need for url.content()
why use #Url.Content
If possible please change avoid storing html in database

How do I redirect requests for certain images in ASP.NET MVC 4?

I'm integrating a 3rd party jquery plugin into a page on my ASP.NET MVC website and I have found that it expects that the images are in an img folder relative to the page it is on. It generates img tags looking like this:
<img src="img/blah.jpg">
The trouble is, my page is at a URL like mysite.com/mycontroller/view/id and so there is no easy way of putting the img folder in the right place for it to pick up the images. I need the img tags to be like this:
<img src="/Content/img/blah.jpg">
Obviously I could edit the 3rd party javascript to output a different path every time it creates an img tag, but I am wondering whether there is a better way in ASP.NET MVC (perhaps with rerouting?).
(I am very new to ASP.NET MVC and web development, so please tell me if I'm going about this in completely the wrong way).
I would recommend avoiding trying to fix this via routing. It's going to be easier and most performant to edit the script to have the path be correct. Fixing it in the client script is likely as easy as a find and replace or just editing a single string object.

asp mvc file upload

I have a form in asp.net mvc 3 project with some properties (a name and some extra properties who need to be filled in).
What i also need is a file to upload in the same form.
I placed an input type "file" and that works when i use Request.File the file is ok.
But i'm also using form validation, so when my name is not filled in, it's not possible to save. That works fine, but then my file is cleared..
Someone who has a good example to use file upload in a form? (with other fields and validation)
In addition to #Neil Knight's excellent references in his answer, if you're using ajax (and you probably are or will be to leverage MVC's ability to facilitate partial page refreshes) the jquery plugin here has proved itself useful in enabling file upload without a full page navigation.

CKEditor Image Upload

I am looking to include CKEditor in a project I am working on and I need the image upload support provided by the CKFinder plugin, however I do not particularly need the rest of the CKFinder tool and thus purchasing a license is a little overkill. Has anyone taken the time to implement a custom image uploader for CKEditor 3 that will work with ASP.NET MVC? If need be I can create my own, just wanted to check here first.
Alternatively, does anyone know of a decent WYSIWYG editor on par with CKEditor / Cute Editor that supports image uploading and will work in ASP.NET MVC?
Here is a image uploader I originally wrote in ASP.NET WebForms for Fckeditor (hence the theme no longer matches), that I've modified to work with Ckeditor.
https://github.com/mcm-ham/ckeditor-image-uploader
Update: I've now added an example showing how you can add this WebForms image uploader to a MVC project.
Update 2: I've now added a Razor Pages version which can be used in .NET Core MVC projects.
Here is a tutorial on how to upload image with ASP:NET MVC2 (not Webforms) using CKEditor
http://arturito.net/2010/11/03/file-and-image-upload-with-asp-net-mvc2-with-ckeditor-wysiwyg-rich-text-editor/
I have used ckeditor and the upload control using ASP.NET, but not MVC specifically. I haven't found anything on par with ckeditor that is even close to being as easy to set up or offers the same features.
Not sure of the restrictions for MVC, but I set up file upload support by using the following:
The basic documentation referring mostly to the CKFinder plugin you mentioned:
http://docs.cksource.com/CKEditor_3.x/Developers_Guide/File_Browser_%28Uploader%29
Better documentation on how to implement the upload component:
How can you integrate a custom file browser/uploader with CKEditor?
Otherwise, I believe ckeditor just stuffs all the image bytes in the request object and sends it to the page configured for uploading. This page can take those bytes and do whatever it pleases (i.e. save them to the file system, sql server, etc.) This is where the custom implementation comes in.
Instead of using a page to do the upload, I used an httphandler implementation. The page ckeditor redirects to calls the requisite javascript function to indicate the status of the upload after it is complete, but the handler really controls the actual file upload. The basic implementation for the httphandler I used is at:
http://darrenjohnstone.net/2008/07/15/aspnet-file-upload-module-version-2-beta-1/
Hope this at least gives you a starting point.
UPDATE: found this while searching for some other stuff. Didn't look at in depth, but seems to be right up your alley:
http://interactiveasp.net/blogs/spgilmore/archive/2009/06/03/how-to-support-file-uploads-in-asp-net-mvc.aspx
If you need to implement it quickly and have a reliable solution, you may consider a hosted solution to upload and store images for CKEditor - for example, our plugin:
http://ckeditor.com/addon/uploadcare

Resources