This is a migrated thread and some comments may be shown as answers.

MVC Fileupload with dropdown value

1 Answer 85 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 2
Josh asked on 20 Aug 2014, 06:59 PM
My scenario is simple.  A user selects a course from the dropdown and uses the fileupload to select 1 or more files.  The user hits submit and the file is saved in a file directory along with file data saved in the database.

My dropdown:

        @Html.LabelFor(m => m.selectedCourseID)
        @Html.DropDownListFor(m => m.selectedCourseID, Model._courses)


If I use just a regular <input id="FilePath" title="upload a image" type="file" name="file" />, everything saves correctly.   But, I'd rather use the Kendo Upload.  If I add this:

     <div class="demo-section">
                    @(Html.Kendo().Upload()
                    .Name("Images")
                    )
                </div>

I get the following runtime error:

The ViewData item that has the key 'selectedCourseID' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'.



My viewmodel:

        [Display(Name = "Select a course...")]
        public int selectedCourseID { get; set; }


        public IEnumerable<SelectListItem> _courses { get; set; }   



Is this enough information or should I send you information?   Thanks in advance.


1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 21 Aug 2014, 07:51 AM
Hi Josh,


I assume that the issue is similar to the one, described in the following SO thread i.e. the Model state is not valid and on returning the View, the ViewData is not set correctly. I would suggest to review the thread for a possible solution.

As for the Kendo UI Upload, it's Name is set as id and name attributes to the input element. This might be the reason for the problem, because in the case of a regular input, the name is set to file, but the Upload name is Images.

I hope this information helps.

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Upload
Asked by
Josh
Top achievements
Rank 2
Answers by
Dimiter Madjarov
Telerik team
Share this question
or