Domanda

I have the following pieces of code in my MVC 3 app:

View:

@(Html.Telerik().Upload()
        .Name("insertAttachement")
        .Multiple(false)
        .Async(async => async.Save("InsertUpload", "DocumentMaquette"))
        .Localizable("fr-CH")
                        .ClientEvents(events => events
                                .OnLoad("handleUploadControlLoad")
                                .OnUpload("handleInsertUpload")
                            )
        )

Controller method:

public void InsertUpload(HttpPostedFileBase attachement)
    {
        DocumentMaquetteModel model = new DocumentMaquetteModel();
        model.fileName_DMQ = attachement.FileName;            
    }

JS file event handlers:

    function handleInsertUpload(e) {
    console.log(e.files);
}


function handleUploadControlLoad() {
    // handle buttons
    $(this).parent().find('.t-button.t-grid-insert, .t-button.t-grid-cancel').remove();

    // schedule grid refresh on window close
    $(this).closest('.t-window').on('close', refreshGrid);
}
function refreshGrid() {
    $('.t-grid').data('tGrid').ajaxRequest();
}

The output in the console is:

[Object]
0: Object
extension: ".odt"
name: "ListeDeParticipantsParSP.odt"
rawFile: File
size: 761691
__proto__: Object
length: 1
__proto__: Array[0]

But in the controller method I get an NullReferenceException exception when i try to get the file name from the attachment, since the parameter is null.

Any information on this is more then welcome.

Thanks, Silviu

È stato utile?

Soluzione

Well, seconds after posting the question, and the answer came. It seems that the Telerik control uses the name given to the Upload to send the file parameter to the method. So, the method used on Save should always have the HttpPostedFileBase parameter named exactly as the control. In this case, the method should take a parameter named insertAttachement. Go figure!

Thanks for your time.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top