populate the upload control after a post with a false ModelState.IsValue

6 posts, 0 answers
  1. Logan
    Logan avatar
    32 posts
    Member since:
    Apr 2013

    Posted 18 Feb 2015 Link to this post

    I have a kendo upload control that gets posted with a form that has a variety of other fields.  This works great when the user fills everything out correctly, the problem comes when there is an error with the post that causes ModelState.IsValid to be false.  Normally I would repopulate the model and the form would have all of the entered values.

    I cannot find a way to populate the kendo upload control so the old HttpPostedFileBase gets reposted on the next form post.  Is this possible?


    Thanks,
    Logan
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 19 Feb 2015 Link to this post

    Hello Logan,

    During the initialization of the widget we are checking if the value of the underlying input element is not empty i.e. if there are any previously selected files in order to load them directly. If you assure that the value of input is retained at your end, the files will be loaded in the list.

    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.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Logan
    Logan avatar
    32 posts
    Member since:
    Apr 2013

    Posted 19 Feb 2015 in reply to Dimiter Madjarov Link to this post

    So would I feed the HttpPostedFileBase that comes out during a post back into the value of the Upload controller? 

  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 20 Feb 2015 Link to this post

    Hello Logan,

    If the Model State is not cleared and the same view is returned, the value of the form fields is retained. If this is the case at your end, the Upload widget will detect that value of the underlying input is not empty and display the file to the list.

    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.

     
  6. Paul
    Paul avatar
    28 posts
    Member since:
    Mar 2013

    Posted 29 Sep 2015 in reply to Dimiter Madjarov Link to this post

    We are experiencing the same issue as above, using Q2 2015 release.

    The upload control is rendered via en editor template:

     

    @model HttpPostedFileWrapper
     
    @{
        var fileUpload = Html.Kendo()
               .Upload()
               .Name(ViewData.TemplateInfo.HtmlFieldPrefix)
               .Multiple(false)
               .HtmlAttributes(new { accept = ".png,.jpg,.gif" });
    }
     
    @if (Model != null && File.Exists(Model.FileName))
    {
        var fileInfo = new FileInfo(Model.FileName);
        fileUpload.Files(f => f.Add()
            .Name(fileInfo.FullName)
            .Size(fileInfo.Length)
            .Extension(fileInfo.Extension));
    }
     
    @fileUpload

    This works absolutely fine in normal circumstances. However, if a model state error is picked up and the view returned, the upload control has no files. As you can see in the above example we even made an attempt to add in the files manually if the model property has data - this isn't working either.

     

    I can also confirm that the modelstate is not being cleared in the controller method.

     

    Any ideas?

     

    Regards,

     

    Paul

  7. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 30 Sep 2015 Link to this post

    Hello Paul,

    We cannot state for sure what is the reason for the undesired behavior. Please send us an isolated runnable example that demonstrates the case here or in a separate support ticket, so we could take a look.

    Regards,
    Dimiter Madjarov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready