I have already created custom Edit Template for property:
And Save method
It saves the file without problem, but Contact.PhotoFileName is not changed so the PopUp form is not submited at all.
How do I change the value of PhotoFileName so i can save it to database?
6 Answers, 1 is accepted
You can use the widget's success event and fill in some hidden field in the edit form. The Upload component does not have a value during submit when async uploading is used.
the Telerik team
I have the same problem with uploading a file inside a grid popup. I'm pretty new to using mvc/kendo so I may not be doing this properly, and not very good in js.
You said to fill in a hidden field from the Success/Upload event of the Upload widget but I can't get it to work. I'm not even sure whether it's suppose to go to the Action of the Save method (async Save) upon selecting a file or after when I click the Update button on the popup.
popup template .cshtml
Please help thanks in advance
I don't see where the Upload's success event is used in the provided code snippets. The handler should be used to set some value to a hidden field that belongs to the Model. In this way the submitted form will contain information that a file has been uploaded. All this is needed only if the uploaded file is required.
>> I'm not even sure whether it's suppose to go to the Action of the Save method (async Save) upon selecting a file or after when I click the Update button on the popup.
In the provided configuration, the UploadImage action method should be hit as soon as a file is selected, because AutoUpload is set to True and the upload method is asynchronous.
the Telerik team
I tried exactly the way you suggested, but the update is posting old value of the image name instead of the new one. I have made use of hidden field for that model field.
If the new file is successfully uploaded and the hidden field is populated with the new name in the Upload's success event, then how is the old name submitted? Did you debug the code to check for anything unusual?
Please send a runnable demo if you need further assistance.
The problem is now solved. Now I am using editor template for only one field the image one. and placed the [UIHint("")] attribute over the model property. And its working perfectly now.
Earlier code I couldn't figure out how the old value was getting posted. I debugged right across using firebug.
On doing $("ImageName").val() , this was giving the current value but the one that was being posted was the old value.
Thanks anyways, everything's fine now