ASP.NET MVC HttpPostedFileBase pass file to server without input file - asp.net-mvc

I wonder if there is a posibility not to use input file tag and pass file to server. For example, i want to pass image that is shown in <img /> tag.

You can use the javascript XHR object to upload a file to the server. This approach does not use HttpPostedFileBase. There's a good example of how to do it here: File API File Upload - Read XMLHttpRequest in ASP.NET MVC

Related

How to post/upload a file from a client application to MVC Web Application

I would like to post/upload my log.csv file from client(mobile) application to my server. My MVC4 web application is running on IIS7 environment.
I'm not sure how to set MVC controller's parameters and also how to post my file to MVC web application.
My mobile application is developed by C# with unity3D.
Please give me some hints!
Uploading a file in Asp.Net MVC application is very easy.
The posted file is automatically available as a HttpPostedFileBase
parameters in the action of the controller.
For uploading a file on the server you required to have a file input
control with in html form having encoding type set to
multipart/form-data.
The default encoding type of a form is
application/x-www-form-urlencoded and this is no sufficient for
posting a large amount of data to server.
How to do it.. Step By Step Explained Here
Put a file input onto your page, this will allow the user to select a file to upload (ensure you add enctype="multipart/form-data"):
<form action="Url To Your Action Method here" method="POST" enctype="multipart/form-data">
<input type="file" name="myFile"/>
<form />
And then make an action method which receives the file in your MVC application:
//ensure the name of the parameter is the same as the name of the input
[HttpPost]
public ActionResult ReceiveFile(HttpPostedFileBase myFile)
{
}

Grails File Upload + tagLib

If I want to change create my Tag Library for file Upload via ajax, then what changes I have to make into tag in grails.
I have code for file upload via ajax and using that I want to create tag library which upload file and also submit form through ajax...
what I have do for that??
Have you run this command? This creates the necessary files and you just actually write code in those files. Bascially you just genereate HTML in those. Here is an example of a taglib http://www.howardism.org/Technical/Groovy/Useful_Taglibs.html
Hope this helps !!!

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.

Multiple file uploads 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

mvc and img tags, which to use?

when specifying the src of an img tag, must i convert the relative path to absolute? please post examples and why not use runat="Server"
Because ASP.NET MVC views are in a separate folder, your best option is to use the
<%= Url.Content("~/ImagesFolder/image.gif") %>
to get the exact path of the image.
All Url.Content does is return the exact path of a specific file using its relative url so it can be used for ANY file in your web application (.js .css .txt etc.).
Alternatively, a better implementation for images is Html.Image() which is available in the MVC Futures (I can't find the .dll link) and I think in the new version of ASP.NET MVC
If you can't find them, check out this post
Where is Html.Image in ASP .NET MVC RC?
<img src="<%=Url.Content("~")%>MyImageFolder/logo.png"/>
runat=server creates a server control in the code behind, it is not really a usefull concept in MVC where you would not want to access properties of the control on the server.

Resources