clickhas.blogg.se

Jquery ajax file upload example asp.net mvc
Jquery ajax file upload example asp.net mvc





jquery ajax file upload example asp.net mvc

If that is the case, then you may want to consider using one of the following popular uploading libraries or tools out there : If these issues still persist, you might want to consider using a specific jQuery or Javascript library for uploading files like one of those mentioned below :

#JQUERY AJAX FILE UPLOAD EXAMPLE ASP.NET MVC CODE#

I'm having no issues at all using the example that I provided above and you can see that the File is being populated as expected when the button is clicked below :Īre you sure that your particular AJAX call is actually being executed ( you can try placing an alert in the code that triggers it)? You might want to use the Developer Tools (F12) within your browser to ensure that this is actually occurring and

jquery ajax file upload example asp.net mvc

If you plan on handling this extensively, it can sometimes be easier to either use a specific file-uploading library to handle this or using the default form submittal behavior.Ĭould you consider posting what your entire Controller and Views look like? In the above example, the file parameter is populated as it would be expected. Public void Import(HttpPostedFileBase file) You can try making the following adjustments to your code as seen in the example below ( ensuring your Controller Action is decorated with ) :Įxample Controller namespace Testing_Application.Controllers Which after posting, you can see that both values are being populated with no major changes :ĮxampleController.cs public class ExampleController : Controller Public void Import(HttpPostedFileBase file, string SelectedItem) If you would prefer you could add an additional parameter to more easily access the value within your MVC Controller Action : You shouldn't have to change anything from the previous AJAX call ( formdata should contain everything that you need). The name attribute (and id) are going to automatically be set by the DropDownListFor() Helper based on whatever the name of the property you are using is ( so in this case it would be SelectedItem) : Model.SelectedItem, Model.List)%>īecause this sets your name attribute, it will also cause your element to be properly serialized within your by the following call : // Serialize your form However, you'll be accessing it by it's "name" attribute which is the most important attribute when it comes to serializing data.

jquery ajax file upload example asp.net mvc

Hi Rion Williams, I have another question to ask you.įirstly, this should really be posted as another question as your original question was closed a month ago.Īnyways, if you want to pass that parameter across, you should be able to capture the value as expected within Javascript. Someone can help me, thank you in advance When I execute this, file in my controller is null. In order to import data from file excel and display data in ascx page, I want to pass a file as a parameter to the controller via a jQuery function here is my code:







Jquery ajax file upload example asp.net mvc