We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

On post to SaveDefault IEnumerable is null

I'm using the UploadBox control and using the example code to implement the SaveDefault method, e.g.:

public ActionResult SaveDefault(IEnumerable<HttpPostedFileBase> UploadDefault)
        {
            foreach (var file in UploadDefault)
            {
         ...
        }
     ...
}

The problem is that UploadDefault is null... If I start from a blank project or run a sample project it works correctly. 
I first came across the problem in some older code - I added in SyncFusion to the project and on running the UploadDefault was null. I assumed it was just some code clash. or some hang over of the way I had implemented the MVC code.
I can actually see that the client code is returning (what appears to be) to the server an HTML response with the file encoded - so does not appear to be a client issue but server side processing

However, I started another new project and now that project is now returning null. I've checked all the things I can - has anyone else come across this? Have I missed something simple (e.g. jQuery version clash, incompatiblity with .NET 4.5.1)?

Thanks,


6 Replies

PP Prasanth Palani Syncfusion Team August 14, 2015 01:32 PM UTC

Hi Aubyn,
 Thanks for using Syncfusion products,
In MVC model binding, we specify the name of the component in the controller to get the values. Similarly here you need to specify the name of the uploadbox component in the controller. We maintain the “id” of the component as the “name”. So please specify the “id” of the component in the controller as shown below and you will get the file details in the IEnumerable object.

View


@Html.EJ().Uploadbox("FileUpload").SaveUrl(@Url.Action("SaveDefault")).RemoveUrl(@Url.Action("RemoveDefault"))



Controller


public ActionResult SaveDefault(IEnumerable<HttpPostedFileBase> FileUpload)

        {

            foreach (var file in FileUpload)



We have prepared simple sample to showcase your requirement, please check it,
http://www.syncfusion.com/downloads/support/directtrac/119920/UploadBoxsyn114344373.zip
If still you face any difficulties please revert back the provided sample based on your application to showcase the issue that you are facing and we will be happy to help you.
To know about the list of properties, methods and events supported by any JS component, go to the online help link for JS (http://helpjs.syncfusion.com/js/overview) and click on the “API reference” section and navigate to the particular component. For example, to know all the available options in DatePicker check the following link,
http://helpjs.syncfusion.com/js/api/ejdatepicker
For getting started and to know about the important features in any particular component, go to the help link and click on the particular component. For example, getting started and key features in DatePicker can be found in
http://helpjs.syncfusion.com/js/datepicker/overview

Please let us know if you have further queries.
 
Regards,
Gopal L


AC Aubyn Crawford August 17, 2015 07:52 PM UTC

I understand (now!) the relationship there, I knew there had to be a simple explanation - glad I posted. Thanks  


GL Gopal Lakshmanan Syncfusion Team August 18, 2015 05:38 AM UTC

Hi Aubyn,
           Thanks for the update, please let us know if need further asssitance.
 
 
Regards,
Gopal.L




EV enzo vini July 13, 2023 08:27 AM UTC

If you're encountering a situation where the IEnumerable object is null when using a "POST" request to save default values, there are a few potential causes and troubleshooting steps you can take:

  1. Verify the Data Source: Ensure that the data source from which you're retrieving the IEnumerable object is properly initialized and not null. Check the code that retrieves or populates the IEnumerable collection to make sure it's correctly fetching the data.

  2. Check the Request Payload: Make sure that you are sending the correct request payload when making the "POST" request. Ensure that the IEnumerable object is included in the payload and is not null before sending it to the server.

  3. Handle Null Values on the Server Side: On the server side, you can check for null values before attempting to save or process the IEnumerable object. Implement appropriate null checks and handling mechanisms to prevent errors when the object is null.

  4. Debugging and Logging: Add logging statements or use a debugger to inspect the code and track the flow of data. Check for any intermediate steps or transformations that could be causing the null value.

  5. Validate the Controller Action: Ensure that the controller action method receiving the "POST" request is correctly designed to accept and process the IEnumerable object. Double-check the method signature, parameter types, and any model binding or validation logic.

By carefully examining these potential causes and troubleshooting steps, you should be able to identify the source of the null value and implement the necessary adjustments to resolve the issue.



SS Shereen Shajahan Syncfusion Team July 14, 2023 06:53 AM UTC

Hi Enzo,

Thank you for your detailed instructions.

Regards,

Shereen



LM Lydia Miller July 31, 2023 05:45 AM UTC

Hi Guys,

The null check is missing before saving the IEnumerable to the default value, which could result in a NullReferenceException if the IEnumerable is null. Always ensure to validate the IEnumerable for null before performing any operations to avoid potential runtime errors.


Loader.
Live Chat Icon For mobile
Up arrow icon