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

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

5 Answers 304 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Logan
Top achievements
Rank 1
Veteran
Logan asked on 18 Feb 2015, 09:18 PM
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

5 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 19 Feb 2015, 09:31 AM

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.

 
0
Logan
Top achievements
Rank 1
Veteran
answered on 19 Feb 2015, 12:42 PM
So would I feed the HttpPostedFileBase that comes out during a post back into the value of the Upload controller? 

0
Dimiter Madjarov
Telerik team
answered on 20 Feb 2015, 12:18 PM

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.

 
0
Paul
Top achievements
Rank 1
answered on 29 Sep 2015, 02:47 PM

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

0
Dimiter Madjarov
Telerik team
answered on 30 Sep 2015, 07:43 AM

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
Tags
Upload
Asked by
Logan
Top achievements
Rank 1
Veteran
Answers by
Dimiter Madjarov
Telerik team
Logan
Top achievements
Rank 1
Veteran
Paul
Top achievements
Rank 1
Share this question
or