MVC Fileupload with dropdown value

2 posts, 0 answers
  1. Josh
    Josh avatar
    4 posts
    Member since:
    Jul 2014

    Posted 20 Aug 2014 Link to this post

    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">

    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.

  2. Dimiter Madjarov
    Dimiter Madjarov avatar
    2213 posts

    Posted 21 Aug 2014 Link to this post

    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.

    Dimiter Madjarov

    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.

Back to Top