Post Form data with also some input files to Web Api - asp.net-mvc-3

Is there any updated example to upload files with a form with fields and file inputs that post to a mvc4 webapi controller?
I am trying to post with Jquery axax to a asp.net mvc4 ApiController.
I used the Jquery file Upload plugin for the client side part.
As the webapi seems not to support multiform data I tried to solve with this configuration formatter but still looking for a better solution

See: http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2
(Scroll down to "Supporting Multipart MIME Data")
I have not actually tried this with the jQuery plugin, only with plain HTML forms.

Related

File input does not post in ASP.NET Ajax.BeginForm. Why?

Let me first be clear about what I'm not asking. I can see that the native ASP.NET MVC Ajax.BeginForm does not handle posting files from within an AJAX form post. There are answers I've seen that seem to establish this fact, and to offer an assortment of workarounds via jQuery plugins, etc:
Ajax.BeginForm in MVC to upload files
File upload with ajax in asp.net mvc
I'm not asking whether it can't be done, and I'm not asking for a workaround. I'm hoping someone can explain why it can't be done.
How is the AJAX form post being handled in MVC such that file inputs do not post? I guess I had always assumed that it was being handled at a base level just like a full post, but with some javascript trimmings that prevented a full page reload. Apparently that's not the case. Is the form submitted via javascript something like jQuery's $('#form').submit()? What's happening under the covers?

Is there anyway to submit form which will have also upload multiple file using ajax in asp.net mvc 3/4?

I want to submit form using ajax.but the problem is that ,i found ajax doesn't support file upload while we submit form.Is there any other way we can do it using ajax because i don't want to refresh page using normal form submit.Please help any suggestion will be very helpful for me.
thanks in advance
You can do this in several ways:
First:
Use canvas
How to save a HTML5 Canvas as Image on a server
Second:
Use some js library like:
http://blueimp.github.io/jQuery-File-Upload/ or
https://github.com/LPology/Simple-Ajax-Uploader
Third:
Use html5 FormData
How to upload a file using jQuery.ajax and FormData

How to upload a file using Ajax request in rails 2.3

I have a rails 2.3 application.
I am using Ajax request to submit the form content. In my form, I have a provision to upload files.
Issue with the form is, if I added a file to the form and submitted the form content, I am getting an error "Error: NS_ERROR_XPC_BAD_OP_ON_WN_PROTO: Illegal operation on WrappedNative prototype object Source" in "jquery-1.4.4.min.js" file and the form is submitting normally without using ajax request. But, the form is submitting form content using Ajax when there is no file selected to upload.
Can anyone please tell me how to upload file using Ajax request.
I found a solution for my above mentioned requirement at the following url. Hope it may help some one.
http://priyanka-railsdeveloper.blogspot.in/2011/11/allow-ajax-upload.html

Need to Save HTML markup from a form element

I want to save html markup in my database for a field from an ASP.Net MVC2 application. Upon reading I found that using the [ValidateInput(false)] attribute lets you do that. But it is not working for me. The data comes from the extjs htmleditor form element.
Anyone has any ideas? Is there something else I need to do? Any setting in web.config?
see ASP.NET Request Validation Exception Even When Validation Is Disabled

Live Search using ASP.NET MVC and AJAX

I am looking to implement a live search in my MVC app similar to this site when you type in a question and results come up that are similar or like the search on http://www.krop.com/
I have the search code all working and results updated. I just need to know how to add the AJAX to the MVC framework (I know this site was built using it) so that when I type the results are updated.
I had this all working in normal ASP.NET Forms app.
what you need to do it attach to Jquery onchage event handler, and then call some ajax method of jquery ($.load , $.ajax etc...) and the information from a specified controller. asp.net mvc controller can return json results so you can later manipulate it in your javascript code.
if you have any other questions go ahead and ask.
An ASP.NET MVC site will have AJAX and JQuery available by default.
Mike Bosch's Blog can give you some pointers on this

Resources